{"record":{"id":"8be8df85ac4725af","repo":"gchq/CyberChef","slug":"unable-to-find-compression-function","errorCode":null,"errorMessage":"Unable to find compression function","messagePattern":"Unable to find compression function","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/LZStringCompress.mjs","lineNumber":49,"sourceCode":"                name: \"Compression Format\",\n                type: \"option\",\n                defaultIndex: 0,\n                value: COMPRESSION_OUTPUT_FORMATS\n            }\n        ];\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        const compress = COMPRESSION_FUNCTIONS[args[0]];\n        if (compress) {\n            return compress(input);\n        } else {\n            throw new OperationError(\"Unable to find compression function\");\n        }\n    }\n\n}\n\nexport default LZStringCompress;\n","sourceCodeStart":31,"sourceCodeEnd":56,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/LZStringCompress.mjs#L31-L56","documentation":"Thrown by LZString Compress when the selected compression format does not resolve to a function in the COMPRESSION_FUNCTIONS map. The format is a dropdown bound to COMPRESSION_OUTPUT_FORMATS, so this is a defensive guard: it triggers only if the argument is not a key in the map (hand-edited recipe, a format listed in options but missing from the map, or args[0] undefined).","triggerScenarios":"A recipe supplies a format string absent from COMPRESSION_FUNCTIONS. A mismatch where a value in COMPRESSION_OUTPUT_FORMATS has no matching entry in COMPRESSION_FUNCTIONS (data/config drift). Programmatic call with an unrecognised format.","commonSituations":"Hand-editing the recipe's option value. Updating the format list without the function map (or vice versa). Importing recipes from a different CyberChef version.","solutions":["Pick a format from the operation's dropdown (it lists only valid options).","When calling programmatically, check Object.keys(COMPRESSION_FUNCTIONS) for the format first.","Keep COMPRESSION_OUTPUT_FORMATS and COMPRESSION_FUNCTIONS in sync when adding formats.","Reset the option to its default index to recover a valid value."],"exampleFix":"// before: unknown format\nchef.LZStringCompress(text, ['UnknownFormat']);\n// after: a format present in the map\nchef.LZStringCompress(text, ['Base64']);","handlingStrategy":"validation","validationCode":"function ensureCompressionFormat(format) {\n  if (!Object.prototype.hasOwnProperty.call(COMPRESSION_FUNCTIONS, format))\n    throw new Error(`Unknown LZ compression format: ${format}`);\n  return format;\n}","typeGuard":"function isKnownCompressionFormat(f) {\n  return Object.prototype.hasOwnProperty.call(COMPRESSION_FUNCTIONS, f);\n}","tryCatchPattern":"try {\n  return chef.LZStringCompress(input, [format]);\n} catch (e) {\n  if (/Unable to find compression function/.test(e.message))\n    throw new Error('Pick a format listed in the dropdown');\n  throw e;\n}","preventionTips":["Choose the format from the operation dropdown.","Keep COMPRESSION_OUTPUT_FORMATS and COMPRESSION_FUNCTIONS in sync.","Validate the key exists before calling programmatically."],"tags":["lzstring","compression","argument-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}