ssssssss-team/spider-flow · error · Error

Bad type: ' + utils.getClass(val)

Error message

Bad type: ' + utils.getClass(val)

What it means

jsontree's utils.getType() switches on the result of Object.prototype.toString.call(val) and supports only a fixed set (array, object, etc.). Any value whose class tag is not in the switch reaches the fallback throw, reporting the unrecognized [object ...] class.

Solutions

  1. Sanitize data before rendering: JSON.parse(JSON.stringify(data)) so only JSON-safe types remain
  2. Replace or map unsupported values (functions, undefined, Dates) to strings or null in preprocessing
  3. Extend the switch in utils.getType (and Node.CONSTRUCTORS) to cover the missing class

Example fix

// before
render(data); // data may contain functions/Dates
// after
render(JSON.parse(JSON.stringify(data, function(k, v) {
  return typeof v === "function" ? String(v) : v;
})));
Defensive patterns

Strategy: validation

Validate before calling

var SUPPORTED = ["[object Boolean]","[object Number]","[object String]","[object Array]","[object Object]"];
function isRenderable(v) {
  return v != null && SUPPORTED.indexOf(Object.prototype.toString.call(v)) !== -1;
}
if (!isRenderable(data)) data = sanitize(data); // strip/map functions, dates, undefined

Type guard

function isPlainJsonValue(v) {
  var t = Object.prototype.toString.call(v);
  return ["[object Array]","[object Object]","[object String]","[object Number]","[object Boolean]"].indexOf(t) !== -1;
}

Try / catch

try {
  tree.render(data);
} catch (e) {
  if (/Bad type:/.test(e.message)) {
    tree.render(JSON.parse(JSON.stringify(data)));
  } else { throw e; }
}

Prevention

When it happens

Trigger: Passing a value of an unsupported type into jsontree's tree-building/getType path — e.g. undefined, function, date, regexp, symbol, or a boxed/null edge case — via new Node() or rendering JSON containing such values.

Common situations: Feeding the tree raw JavaScript values instead of JSON-parseable data, JSON responses including dates/functions that were not serialized, or a minified/partial build where getType's supported cases diverge from Node.CONSTRUCTORS.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.


AI-assisted analysis of ssssssss-team/spider-flow@c799cca99c (2026-09-08). Data as JSON: /api/errors/73032ea6108dc5ed. Report an issue: GitHub.

Appendix: source

Thrown at spider-flow-web/src/main/resources/static/js/jsontree/jsontree.js:55

                case 'number':
                    return 'number';
                
                case 'string':
                    return 'string';
                
                case 'boolean':
                    return 'boolean';
            }
            
            switch(utils.getClass(val)) {
                case '[object Array]':
                    return 'array';
                
                case '[object Object]':
                    return 'object';
            }
            
            throw new Error('Bad type: ' + utils.getClass(val));
        },
        
        /**
         * Applies for each item of list some function
         * and checks for last element of the list
         * 
         * @param obj {Object | Array} - a list or a dict with child nodes
         * @param func {Function} - the function for each item
         */
        forEachNode : function(obj, func) {
            var type = utils.getType(obj),
                isLast;
        
            switch (type) {
                case 'array':
                    isLast = obj.length - 1;
                    
                    obj.forEach(function(item, i) {

View on GitHub (pinned to c799cca99c)