{"record":{"id":"41859654192bdbdd","repo":"gchq/CyberChef","slug":"no-data","errorCode":null,"errorMessage":"No data","messagePattern":"No data","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"warning","filePath":"src/core/operations/FrequencyDistribution.mjs","lineNumber":50,"sourceCode":"                \"type\": \"boolean\",\n                \"value\": true\n            },\n            {\n                \"name\": \"Show ASCII\",\n                \"type\": \"boolean\",\n                \"value\": true\n            }\n        ];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {json}\n     */\n    run(input, args) {\n        const data = new Uint8Array(input);\n        if (!data.length) throw new OperationError(\"No data\");\n\n        const distrib = new Array(256).fill(0),\n            percentages = new Array(256),\n            len = data.length;\n        let i;\n\n        // Count bytes\n        for (i = 0; i < len; i++) {\n            distrib[data[i]]++;\n        }\n\n        // Calculate percentages\n        let repr = 0;\n        for (i = 0; i < 256; i++) {\n            if (distrib[i] > 0) repr++;\n            percentages[i] = distrib[i] / len * 100;\n        }\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/FrequencyDistribution.mjs#L32-L68","documentation":"Thrown by the Frequency Distribution operation when the input ArrayBuffer is empty (data.length === 0). The operation computes per-byte percentages that divide by data length, so it refuses to run on zero bytes. This is a guard against a meaningless/NaN result rather than a data-corruption problem.","triggerScenarios":"Feeding an empty input into the operation; an upstream op producing a zero-length ArrayBuffer; a recipe whose input was fully consumed/filtered out before this step.","commonSituations":"Empty recipe input box; a 'Remove'/'Filter' operation that deleted all bytes; feeding a string input that converted to zero bytes; testing the op with no data.","solutions":["Provide non-empty byte data as input.","Check upstream operations are not producing empty output.","If empty input is expected in your pipeline, skip this op conditionally."],"exampleFix":"// before: empty buffer\nfreq.run(new ArrayBuffer(0), args) // throws\n// after: guard upstream\nif (input.byteLength > 0) freq.run(input, args); else /* skip */","handlingStrategy":"validation","validationCode":"// Skip the op on empty input rather than letting it throw\nif (input instanceof ArrayBuffer && input.byteLength === 0) {\n  // return empty result; do not call freq.run()\n}","typeGuard":"function hasBytes(buf) {\n  return (buf instanceof ArrayBuffer ? buf.byteLength : buf?.byteLength ?? 0) > 0;\n}","tryCatchPattern":"try {\n  freq.run(input, args);\n} catch (e) {\n  if (e.type === 'OperationError' && e.message === 'No data') {\n    // empty input; produce an empty/zero distribution instead\n  } else throw e;\n}","preventionTips":["Gate the operation on non-empty input in your pipeline.","Check upstream filter/remove ops do not zero out the buffer.","Handle 'No data' as an expected empty-input case, not a crash."],"tags":["statistics","empty-input","input-validation","arraybuffer"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}