{"record":{"id":"3f187f024cc366ae","repo":"gchq/CyberChef","slug":"error-translating-from-dish-enumlookup-this-type","errorCode":null,"errorMessage":"Error translating from ${Dish.enumLookup(this.type)} to ArrayBuffer: ${err}","messagePattern":"Error translating from (.+?) to ArrayBuffer: (.+?)","errorType":"exception","errorClass":"DishError","httpStatus":null,"severity":"error","filePath":"src/core/Dish.mjs","lineNumber":474,"sourceCode":"                [Dish.BYTE_ARRAY]:      () => Promise.resolve(DishByteArray.toArrayBuffer.bind(this)()),\n            },\n            node: {\n                [Dish.STRING]:          () => DishString.toArrayBuffer.bind(this)(),\n                [Dish.NUMBER]:          () => DishNumber.toArrayBuffer.bind(this)(),\n                [Dish.HTML]:            () => DishHTML.toArrayBuffer.bind(this)(),\n                [Dish.ARRAY_BUFFER]:    () => {},\n                [Dish.BIG_NUMBER]:      () => DishBigNumber.toArrayBuffer.bind(this)(),\n                [Dish.JSON]:            () => DishJSON.toArrayBuffer.bind(this)(),\n                [Dish.FILE]:            () => DishFile.toArrayBuffer.bind(this)(),\n                [Dish.LIST_FILE]:       () => DishListFile.toArrayBuffer.bind(this)(),\n                [Dish.BYTE_ARRAY]:      () => DishByteArray.toArrayBuffer.bind(this)(),\n            }\n        };\n\n        try {\n            return toByteArrayFuncs[isNodeEnvironment() && \"node\" || \"browser\"][this.type]();\n        } catch (err) {\n            throw new DishError(`Error translating from ${Dish.enumLookup(this.type)} to ArrayBuffer: ${err}`);\n        }\n    }\n\n    /**\n     * Convert this.value to the given type from ArrayBuffer\n     *\n     * @param {number} toType - the Dish enum to convert to\n    */\n    _fromArrayBuffer(toType) {\n\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)(),","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/Dish.mjs#L456-L492","documentation":"Thrown by Dish._toArrayBuffer(), the first half of _translate(), wrapping any synchronous exception from the per-type toArrayBuffer function (DishString.toArrayBuffer, DishFile.toArrayBuffer, etc.). It fires only for throws inside the function table lookup/invocation - in the browser the table returns Promises whose rejections are NOT caught here (they reject the outer translate promise). The message names the source Dish type and the inner error.","triggerScenarios":"A Dish whose .value has drifted out of sync with .type (e.g. type is STRING but value is a number) causing DishString.toArrayBuffer to fail; a Dish.FILE in a Node environment where the File API or its content is unavailable; a Dish.BIG_NUMBER whose value is a corrupt {c,e,s} object that BigNumber rejects on serialise.","commonSituations":"An upstream operation mutated dish.value directly without going through set(); running browser-oriented dish translation (File/ListFile) under Node where the File constructor/blob.text behaves differently; a BigNumber that survived valid() but fails ArrayBuffer round-trip due to extreme exponent.","solutions":["Read the inner ${err} in the message - it identifies which Dish*.toArrayBuffer failed and why.","Before calling dish.get(toType)/_translate, assert dish.valid() passes so value and type are consistent.","If the inner error references File/ListFile, confirm you are in an environment with the File API (browser, or Node >= 20 with web File) and the file content is readable.","Avoid mutating dish.value by hand; always use dish.set() so type/value stay consistent."],"exampleFix":"// before\ndish.value = 123; // type still STRING, value now a number\ndish.get(Dish.ARRAY_BUFFER); // _toArrayBuffer throws on DishString path\n\n// after\ndish.set(123, Dish.NUMBER);\ndish.get(Dish.ARRAY_BUFFER);","handlingStrategy":"try-catch","validationCode":"if (!dish.valid()) {\n  throw new Error('Dish value/type inconsistent - fix before translate');\n}\n// then translate","typeGuard":"null","tryCatchPattern":"try {\n  await dish.get(targetType);\n} catch (e) {\n  if (e instanceof DishError && /translating from .* to ArrayBuffer/.test(e.message)) {\n    // inner translation failed - inspect e.message for the cause\n  }\n  throw e;\n}","preventionTips":["Never mutate dish.value by hand; use set() to keep value and type consistent.","Call dish.valid() before any translate/get/presentAs.","Confirm File/ListFile paths run where the File API exists."],"tags":["dish","translation","arraybuffer","disherror"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}