alibaba/arthas · error · Error

Configuration should be an object

Error message

Configuration should be an object

What it means

Thrown by the configuration setter when typeof configuration !== 'object'. Note typeof null === 'object' and typeof [] === 'object', so null and arrays pass this check; primitives like string, number, boolean, undefined, bigint, and symbol fail. The component stores whatever object is given and later reads config items by key via getConfigItemOrDefault.

Source

Thrown at labs/arthas-jfr-frontend/public/flame-graph/flame-graph-class.js:625

    }
    if (typeof dataSource.format !== 'string') {
      throw new Error('Illegal dataSource format type, must be string');
    }
    let format = dataSource.format.toLowerCase();
    if ('line' !== format && 'tree' !== format) {
      throw new Error("Illegal dataSource format, must be 'line' or 'tree'");
    }
    this.$dataSource = dataSource;
    this.render(true, true);
  }

  get dataSource() {
    return this.$dataSource;
  }

  set configuration(configuration) {
    if (typeof configuration !== 'object') {
      throw new Error('Configuration should be an object');
    }
    this.$configuration = configuration;
  }

  get configuration() {
    return this.$configuration;
  }

  getConfigItemOrDefault(name, def) {
    if (this.$configuration && this.$configuration[name]) {
      return this.$configuration[name];
    }
    return def;
  }

  _(name, def) {
    return this.getConfigItemOrDefault(name, def);
  }

View on GitHub (pinned to 21cf2e9ba5)

Solutions

  1. Pass a plain options object, e.g., element.configuration = { theme: 'dark' }.
  2. If you have no config, omit the assignment or pass null/{} (both accepted).
  3. Parse JSON strings with JSON.parse before assigning.

Example fix

// before
el.configuration = '{"theme":"dark"}'; // string, throws

// after
el.configuration = JSON.parse('{"theme":"dark"}');
// or
el.configuration = { theme: 'dark' };
Defensive patterns

Strategy: type-guard

Validate before calling

if (configuration !== undefined && configuration !== null && typeof configuration !== 'object') {
  throw new TypeError('configuration must be an object');
}
el.configuration = configuration;

Type guard

function isConfigObject(c) { return c == null || (typeof c === 'object' && !Array.isArray(c)); }

Prevention

When it happens

Trigger: Assigning element.configuration = 'dark' (a string) or a number/boolean; passing undefined explicitly; assigning a primitive where an options bag was expected.

Common situations: Confusing a single config flag (e.g., theme) with the whole configuration object; passing a serialized string instead of a parsed object.

Related errors


AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14). Data as JSON: /api/errors/18a60a7402c85d88. Report an issue: GitHub.