{"record":{"id":"514d36faf85e4429","repo":"gchq/CyberChef","slug":"error-translating-from-arraybuffer-to-dish-enuml","errorCode":null,"errorMessage":"Error translating from ArrayBuffer to ${Dish.enumLookup(toType)}: ${err}","messagePattern":"Error translating from ArrayBuffer to (.+?): (.+?)","errorType":"exception","errorClass":"DishError","httpStatus":null,"severity":"error","filePath":"src/core/Dish.mjs","lineNumber":502,"sourceCode":"\n        // Using 'bind' here to allow this.value to be mutated within translation functions\n        const toTypeFunctions = {\n            [Dish.STRING]:          () => DishString.fromArrayBuffer.bind(this)(),\n            [Dish.NUMBER]:          () => DishNumber.fromArrayBuffer.bind(this)(),\n            [Dish.HTML]:            () => DishHTML.fromArrayBuffer.bind(this)(),\n            [Dish.ARRAY_BUFFER]:    () => {},\n            [Dish.BIG_NUMBER]:      () => DishBigNumber.fromArrayBuffer.bind(this)(),\n            [Dish.JSON]:            () => DishJSON.fromArrayBuffer.bind(this)(),\n            [Dish.FILE]:            () => DishFile.fromArrayBuffer.bind(this)(),\n            [Dish.LIST_FILE]:       () => DishListFile.fromArrayBuffer.bind(this)(),\n            [Dish.BYTE_ARRAY]:      () => DishByteArray.fromArrayBuffer.bind(this)(),\n        };\n\n        try {\n            toTypeFunctions[toType]();\n            this.type = toType;\n        } catch (err) {\n            throw new DishError(`Error translating from ArrayBuffer to ${Dish.enumLookup(toType)}: ${err}`);\n        }\n    }\n\n}\n\n\n/**\n * Dish data type enum for byte arrays.\n * @readonly\n * @enum\n */\nDish.BYTE_ARRAY = 0;\n/**\n * Dish data type enum for strings.\n * @readonly\n * @enum\n */\nDish.STRING = 1;","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/Dish.mjs#L484-L520","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read ${err}: a 'Not a valid number' or JSON SyntaxError tells you the buffer content is the problem, not the API.","Confirm the target Dish type is sensible for the data: translate binary to STRING or BYTE_ARRAY first, then parse explicitly.","Wrap dish.get(targetType) / dish.presentAs(targetType) in try-catch to degrade gracefully on unparseable input.","If you control the upstream operation, have it emit a dish type the consumer actually expects."],"exampleFix":"// before\ndish.set(new Uint8Array([0xff,0xfe,0xfd]), Dish.BYTE_ARRAY);\nconst n = dish.get(Dish.NUMBER); // throws: bytes are not a number\n\n// after\ndish.set(new Uint8Array([0xff,0xfe,0xfd]), Dish.BYTE_ARRAY);\nconst text = dish.get(Dish.STRING); // decode, then parse yourself","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  const out = dish.get(Dish.NUMBER);\n} catch (e) {\n  if (e instanceof DishError && /translating from ArrayBuffer to/.test(e.message)) {\n    // target type not achievable from current bytes - fall back to STRING/BYTE_ARRAY\n  }\n}","preventionTips":["Translate binary data to STRING or BYTE_ARRAY first, then parse explicitly.","Ensure upstream operations emit a dish type the consumer expects.","Wrap dish.get/presentAs in try-catch when input may be unparseable."],"tags":["dish","translation","type-conversion","disherror"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}