gchq/CyberChef · error · DishError

Error translating from ArrayBuffer to ${Dish.enumLookup(toTy

Error message

Error translating from ArrayBuffer to ${Dish.enumLookup(toType)}: ${err}

What it means

Thrown by Dish._fromArrayBuffer(toType), the second half of _translate(), wrapping any synchronous exception from the per-type fromArrayBuffer function (DishNumber.fromArrayBuffer, DishJSON.fromArrayBuffer, etc.). The message names the target type and the inner error. After a successful call it also sets this.type = toType.

Source

Thrown at src/core/Dish.mjs:502

        // Using 'bind' here to allow this.value to be mutated within translation functions
        const toTypeFunctions = {
            [Dish.STRING]:          () => DishString.fromArrayBuffer.bind(this)(),
            [Dish.NUMBER]:          () => DishNumber.fromArrayBuffer.bind(this)(),
            [Dish.HTML]:            () => DishHTML.fromArrayBuffer.bind(this)(),
            [Dish.ARRAY_BUFFER]:    () => {},
            [Dish.BIG_NUMBER]:      () => DishBigNumber.fromArrayBuffer.bind(this)(),
            [Dish.JSON]:            () => DishJSON.fromArrayBuffer.bind(this)(),
            [Dish.FILE]:            () => DishFile.fromArrayBuffer.bind(this)(),
            [Dish.LIST_FILE]:       () => DishListFile.fromArrayBuffer.bind(this)(),
            [Dish.BYTE_ARRAY]:      () => DishByteArray.fromArrayBuffer.bind(this)(),
        };

        try {
            toTypeFunctions[toType]();
            this.type = toType;
        } catch (err) {
            throw new DishError(`Error translating from ArrayBuffer to ${Dish.enumLookup(toType)}: ${err}`);
        }
    }

}


/**
 * Dish data type enum for byte arrays.
 * @readonly
 * @enum
 */
Dish.BYTE_ARRAY = 0;
/**
 * Dish data type enum for strings.
 * @readonly
 * @enum
 */
Dish.STRING = 1;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Read ${err}: a 'Not a valid number' or JSON SyntaxError tells you the buffer content is the problem, not the API.
  2. Confirm the target Dish type is sensible for the data: translate binary to STRING or BYTE_ARRAY first, then parse explicitly.
  3. Wrap dish.get(targetType) / dish.presentAs(targetType) in try-catch to degrade gracefully on unparseable input.
  4. If you control the upstream operation, have it emit a dish type the consumer actually expects.

Example fix

// before
dish.set(new Uint8Array([0xff,0xfe,0xfd]), Dish.BYTE_ARRAY);
const n = dish.get(Dish.NUMBER); // throws: bytes are not a number

// after
dish.set(new Uint8Array([0xff,0xfe,0xfd]), Dish.BYTE_ARRAY);
const text = dish.get(Dish.STRING); // decode, then parse yourself
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

try {
  const out = dish.get(Dish.NUMBER);
} catch (e) {
  if (e instanceof DishError && /translating from ArrayBuffer to/.test(e.message)) {
    // target type not achievable from current bytes - fall back to STRING/BYTE_ARRAY
  }
}

Prevention

When it happens

Trigger: Translating an ArrayBuffer of binary garbage to Dish.NUMBER (DishNumber.fromArrayBuffer cannot parse a finite number); translating non-UTF8 bytes to Dish.STRING with a strict decoder; translating bytes that are not valid JSON to Dish.JSON.

Common situations: An operation declares it can consume a NUMBER/JSON dish but the upstream produced arbitrary bytes; chaining operations whose output/input dish types are incompatible; decoding a corrupted/truncated payload.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/514d36faf85e4429. Report an issue: GitHub.