{"record":{"id":"214d77547a7c009e","repo":"gchq/CyberChef","slug":"input-cannot-be-empty","errorCode":null,"errorMessage":"Input cannot be empty.","messagePattern":"Input cannot be empty\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/lib/Bech32.mjs","lineNumber":239,"sourceCode":"    // Check maximum length (90 characters)\n    if (result.length > 90) {\n        throw new OperationError(`Encoded string exceeds maximum length of 90 characters (got ${result.length}). Consider using smaller input data.`);\n    }\n\n    return result;\n}\n\n/**\n * Decode a Bech32/Bech32m string\n *\n * @param {string} str - Bech32/Bech32m encoded string\n * @param {string} encoding - \"Bech32\", \"Bech32m\", or \"Auto-detect\"\n * @returns {{hrp: string, data: number[]}} - Decoded HRP and data bytes\n */\nexport function decode(str, encoding = \"Auto-detect\") {\n    // Check for empty input\n    if (!str || str.length === 0) {\n        throw new OperationError(\"Input cannot be empty.\");\n    }\n\n    // Check maximum length\n    if (str.length > 90) {\n        throw new OperationError(`Invalid Bech32 string: exceeds maximum length of 90 characters (got ${str.length}).`);\n    }\n\n    // Check for mixed case\n    const hasUpper = /[A-Z]/.test(str);\n    const hasLower = /[a-z]/.test(str);\n    if (hasUpper && hasLower) {\n        throw new OperationError(\"Invalid Bech32 string: mixed case is not allowed. Use all uppercase or all lowercase.\");\n    }\n\n    // Convert to lowercase for processing\n    str = str.toLowerCase();\n\n    // Find separator (last occurrence of '1')","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/Bech32.mjs#L221-L257","documentation":"Thrown by decode() in src/core/lib/Bech32.mjs:239 when the input string is falsy or has length 0. The decoder needs at least an HRP, a separator, and a 6-character checksum to do any work, so an empty input is rejected up front as the first validation gate.","triggerScenarios":"decode(''), decode(null), decode(undefined). Any code path that passes user input through without a presence check — e.g. an empty form field, a missing config value, or a variable that was never assigned.","commonSituations":"User submitted an empty form; a variable holding the address was undefined due to a rename or refactor; JSON parsing yielded undefined for a missing field; defensive default of undefined instead of a string.","solutions":["Check for a non-empty string before calling decode.","Provide a clear user-facing error when the input is empty.","Default the variable to '' only if you also short-circuit; better, require a value.","Add a type guard: typeof str === 'string' && str.length > 0."],"exampleFix":"// before\nconst result = decode(maybeUndefinedAddress);\n\n// after\nif (typeof maybeUndefinedAddress !== 'string' || maybeUndefinedAddress.length === 0) {\n  throw new Error('A Bech32 address is required.');\n}\nconst result = decode(maybeUndefinedAddress);","handlingStrategy":"validation","validationCode":"function requireNonEmptyBech32(str) {\n  if (typeof str !== 'string' || str.length === 0) {\n    throw new TypeError('A non-empty Bech32 string is required.');\n  }\n  return str;\n}","typeGuard":"function isNonEmptyString(s) {\n  return typeof s === 'string' && s.length > 0;\n}","tryCatchPattern":"try {\n  decode(input);\n} catch (e) {\n  if (e instanceof OperationError && /Input cannot be empty/.test(e.message)) {\n    // prompt the user for an address\n  }\n}","preventionTips":["Gate form submissions so an empty address never reaches decode.","Default address variables to null and check before decoding, rather than to undefined.","Validate presence at the UI boundary."],"tags":["bech32","decoding","input-validation","empty-input"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}