alibaba/arthas · error · Error

Illegal dataSource format type, must be string

Error message

Illegal dataSource format type, must be string

What it means

Thrown by the dataSource setter when dataSource.format is present but typeof is not 'string' (e.g., a number, boolean, object, or array). The component only accepts a string identifier for the format.

Source

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

  }

  static get observedAttributes() {
    return ['width', 'height', 'downward'];
  }

  attributeChangedCallback(name, oldVal, newVal) {
    if (!this.$dataSource || oldVal === newVal) {
      return;
    }
    this.render(true, false);
  }

  set dataSource(dataSource) {
    if (!dataSource.format) {
      throw new Error("Should specify the format of dataSource: 'line' or 'tree'");
    }
    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;

View on GitHub (pinned to 21cf2e9ba5)

Solutions

  1. Set format to a literal string 'line' or 'tree'.
  2. If the value comes from a variable, coerce with String(x) only after confirming it represents 'line' or 'tree'.
  3. Add a type guard so non-string formats are rejected before reaching the component.

Example fix

// before
el.dataSource = { format: fmtEnum /* number */, data };

// after
el.dataSource = { format: fmtEnum === Fmt.Line ? 'line' : 'tree', data };
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof dataSource.format !== 'string') {
  throw new TypeError('dataSource.format must be a string');
}

Type guard

function isStringFormat(ds) { return !!ds && typeof ds.format === 'string'; }

Try / catch

try { el.dataSource = dataSource; }
catch (e) { if (/must be string/.test(e.message)) { el.dataSource = { ...dataSource, format: String(dataSource.format) }; } else throw e; }

Prevention

When it happens

Trigger: Passing { format: 1 } or { format: true }; passing { format: { type: 'line' } }; a numeric enum/constant leaked in from a typed layer that was not converted to a string.

Common situations: JSON produced by a serializer that turned format into a non-string; TypeScript/enum value coerced unexpectedly; misconfigured payload builder.

Related errors


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