<commit_before>module.exports = function(RED) {
    "use strict";
    var util = require("util");
    var events = require("events");
    const fs = require("fs-extra");
    const path = require("path");
    var debuglength = RED.settings.debugMaxLength || 1000;
    var useColors = RED.settings.debugUseColors || false;
    util.inspect.styles.boolean = "red";
    const { hasOwnProperty } = Object.prototype;

    function DebugNode(n) {
        var hasEditExpression = (n.targetType === "jsonata");
        var editExpression = hasEditExpression ? n.complete : null;
        RED.nodes.createNode(this,n);
        this.name = n.name;
        this.complete = hasEditExpression ? null : (n.complete||"payload").toString();
        if (this.complete === "false") { this.complete = "payload"; }
        this.console = ""+(n.console || false);
        this.tostatus = n.tostatus || false;
        this.statusType = n.statusType || "auto";
        this.statusVal = n.statusVal || this.complete;
        this.tosidebar = n.tosidebar;
        if (this.tosidebar === undefined) { this.tosidebar = true; }
        this.active = (n.active === null || typeof n.active === "undefined") || n.active;
        if (this.tostatus) {
            this.status({fill:"grey", shape:"ring"});
            this.oldState = "{}";
        }

        var hasStatExpression = (n.statusType === "jsonata");
        var statExpression = hasStatExpression ? n.statusVal : null;

        var node = this;
        var preparedEditExpression = null;
        var preparedStatExpression = null;
        if (editExpression) {
            try {
                preparedEditExpression = RED.util.prepareJSONataExpression(editExpression, this);
            }
            catch (e) {
                node.error(RED._("debug.invalid-exp", {error: editExpression}));
                return;
            }
        }
        if (statExpression) {
            try {
                preparedStatExpression = RED.util.prepareJSONataExpression(statExpression, this);
            }
            catch (e) {
                node.error(RED._("debug.invalid-exp", {error: editExpression}));
                return;
            }
        }

        function prepareValue(msg, done) {
            // Either apply the jsonata expression or...
            if (preparedEditExpression) {
                RED.util.evaluateJSONataExpression(preparedEditExpression, msg, (err, value) => {
                    if (err) { done(RED._("debug.invalid-exp", {error: editExpression})); }
                    else { done(null,{id:node.id, z:node.z, _alias: node._alias, path:node._flow.path, name:node.name, topic:msg.topic, msg:value}); }
                });
            } else {
                // Extract the required message property
                var property = "payload";
                var output = msg[property];
                if (node.complete !== "false" && typeof node.complete !== "undefined") {
                    property = node.complete;
                    try { output = RED.util.getMessageProperty(msg,node.complete); }
                    catch(err) { output = undefined; }
                }
                done(null,{id:node.id, z:node.z, _alias: node._alias,  path:node._flow.path, name:node.name, topic:msg.topic, property:property, msg:output});
            }
        }

        function prepareStatus(msg, done) {
            if (node.statusType === "auto") {
                if (node.complete === "true") {
                    done(null,{msg:msg.payload});
                }
                else {
                    prepareValue(msg,function(err,debugMsg) {
                        if (err) { node.error(err); return; }
                        done(null,{msg:debugMsg.msg});
                    });
                }
            }
            else {
                // Either apply the jsonata expression or...
                if (preparedStatExpression) {
                    RED.util.evaluateJSONataExpression(preparedStatExpression, msg, (err, value) => {
                        if (err) { done(RED._("debug.invalid-exp", {error:editExpression})); }
                        else { done(null,{msg:value}); }
                    });
                }
                else {
                    // Extract the required message property
                    var output;
                    try { output = RED.util.getMessageProperty(msg,node.statusVal); }
                    catch(err) { output = undefined; }
                    done(null,{msg:output});
                }
            }
        }
        this.on("close", function() {
            if (this.oldState) {
                this.status({});
            }
        })
        this.on("input", function(msg, send, done) {
            if (hasOwnProperty.call(msg, "status") && hasOwnProperty.call(msg.status, "source") && hasOwnProperty.call(msg.status.source, "id") && (msg.status.source.id === node.id)) {
                done();
                return;
            }
            if (node.tostatus === true) {
                prepareStatus(msg, function(err,debugMsg) {
                    if (err) { node.error(err); return; }
                    var output = debugMsg.msg;
                    var st = (typeof output === 'string') ? output : util.inspect(output);
                    var fill = "grey";
                    var shape = "dot";
                    if (typeof output === 'object' && hasOwnProperty.call(output, "fill") && hasOwnProperty.call(output, "shape") && hasOwnProperty.call(output, "text")) {
                        fill = output.fill;
                        shape = output.shape;
                        st = output.text;
                    }
                    if (node.statusType === "auto") {
                        if (hasOwnProperty.call(msg, "error")) {
                            fill = "red";
                            st = msg.error.message;
                        }
                        if (hasOwnProperty.call(msg, "status")) {
                            fill = msg.status.fill || "grey";
                            shape = msg.status.shape || "ring";
                            st = msg.status.text || "";
                        }
                    }

                    if (st.length > 32) { st = st.substr(0,32) + "..."; }
                    var newStatus = {fill:fill, shape:shape, text:st};
                    if (JSON.stringify(newStatus) !== node.oldState) { // only send if we have to
                        node.status(newStatus);
                        node.oldState = JSON.stringify(newStatus);
                    }
                });
            }

            if (this.complete === "true") {<commit_msg>fix reference error of msg.status in debug node<commit_after>module.exports = function(RED) {
    "use strict";
    var util = require("util");
    var events = require("events");
    const fs = require("fs-extra");
    const path = require("path");
    var debuglength = RED.settings.debugMaxLength || 1000;
    var useColors = RED.settings.debugUseColors || false;
    util.inspect.styles.boolean = "red";
    const { hasOwnProperty } = Object.prototype;

    function DebugNode(n) {
        var hasEditExpression = (n.targetType === "jsonata");
        var editExpression = hasEditExpression ? n.complete : null;
        RED.nodes.createNode(this,n);
        this.name = n.name;
        this.complete = hasEditExpression ? null : (n.complete||"payload").toString();
        if (this.complete === "false") { this.complete = "payload"; }
        this.console = ""+(n.console || false);
        this.tostatus = n.tostatus || false;
        this.statusType = n.statusType || "auto";
        this.statusVal = n.statusVal || this.complete;
        this.tosidebar = n.tosidebar;
        if (this.tosidebar === undefined) { this.tosidebar = true; }
        this.active = (n.active === null || typeof n.active === "undefined") || n.active;
        if (this.tostatus) {
            this.status({fill:"grey", shape:"ring"});
            this.oldState = "{}";
        }

        var hasStatExpression = (n.statusType === "jsonata");
        var statExpression = hasStatExpression ? n.statusVal : null;

        var node = this;
        var preparedEditExpression = null;
        var preparedStatExpression = null;
        if (editExpression) {
            try {
                preparedEditExpression = RED.util.prepareJSONataExpression(editExpression, this);
            }
            catch (e) {
                node.error(RED._("debug.invalid-exp", {error: editExpression}));
                return;
            }
        }
        if (statExpression) {
            try {
                preparedStatExpression = RED.util.prepareJSONataExpression(statExpression, this);
            }
            catch (e) {
                node.error(RED._("debug.invalid-exp", {error: editExpression}));
                return;
            }
        }

        function prepareValue(msg, done) {
            // Either apply the jsonata expression or...
            if (preparedEditExpression) {
                RED.util.evaluateJSONataExpression(preparedEditExpression, msg, (err, value) => {
                    if (err) { done(RED._("debug.invalid-exp", {error: editExpression})); }
                    else { done(null,{id:node.id, z:node.z, _alias: node._alias, path:node._flow.path, name:node.name, topic:msg.topic, msg:value}); }
                });
            } else {
                // Extract the required message property
                var property = "payload";
                var output = msg[property];
                if (node.complete !== "false" && typeof node.complete !== "undefined") {
                    property = node.complete;
                    try { output = RED.util.getMessageProperty(msg,node.complete); }
                    catch(err) { output = undefined; }
                }
                done(null,{id:node.id, z:node.z, _alias: node._alias,  path:node._flow.path, name:node.name, topic:msg.topic, property:property, msg:output});
            }
        }

        function prepareStatus(msg, done) {
            if (node.statusType === "auto") {
                if (node.complete === "true") {
                    done(null,{msg:msg.payload});
                }
                else {
                    prepareValue(msg,function(err,debugMsg) {
                        if (err) { node.error(err); return; }
                        done(null,{msg:debugMsg.msg});
                    });
                }
            }
            else {
                // Either apply the jsonata expression or...
                if (preparedStatExpression) {
                    RED.util.evaluateJSONataExpression(preparedStatExpression, msg, (err, value) => {
                        if (err) { done(RED._("debug.invalid-exp", {error:editExpression})); }
                        else { done(null,{msg:value}); }
                    });
                }
                else {
                    // Extract the required message property
                    var output;
                    try { output = RED.util.getMessageProperty(msg,node.statusVal); }
                    catch(err) { output = undefined; }
                    done(null,{msg:output});
                }
            }
        }
        this.on("close", function() {
            if (this.oldState) {
                this.status({});
            }
        })
        this.on("input", function(msg, send, done) {
            if (hasOwnProperty.call(msg, "status") && msg.status &&
                hasOwnProperty.call(msg.status, "source") && msg.status.source &&
                hasOwnProperty.call(msg.status.source, "id") && (msg.status.source.id === node.id)) {
                done();
                return;
            }
            if (node.tostatus === true) {
                prepareStatus(msg, function(err,debugMsg) {
                    if (err) { node.error(err); return; }
                    var output = debugMsg.msg;
                    var st = (typeof output === 'string') ? output : util.inspect(output);
                    var fill = "grey";
                    var shape = "dot";
                    if (typeof output === 'object' && hasOwnProperty.call(output, "fill") && hasOwnProperty.call(output, "shape") && hasOwnProperty.call(output, "text")) {
                        fill = output.fill;
                        shape = output.shape;
                        st = output.text;
                    }
                    if (node.statusType === "auto") {
                        if (hasOwnProperty.call(msg, "error")) {
                            fill = "red";
                            st = msg.error.message;
                        }
                        if (hasOwnProperty.call(msg, "status") &&
                           msg.status) {
                            fill = msg.status.fill || "grey";
                            shape = msg.status.shape || "ring";
                            st = msg.status.text || "";
                        }
                    }

                    if (st.length > 32) { st = st.substr(0,32) + "..."; }
                    var newStatus = {fill:fill, shape:shape, text:st};
                    if (JSON.stringify(newStatus) !== node.oldState) { // only send if we have to
                        node.status(newStatus);
                        node.oldState = JSON.stringify(newStatus);
                    }
                });
            }

            if (this.complete === "true") {
{'fraction_non_alphanumeric': 0.13054078014184398, 'fraction_numerical': 0.0013297872340425532, 'mean_word_length': 1.420779685264664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7319537', 'n_tokens_mistral': 3576, 'n_tokens_neox': 3379, 'n_words': 704}