gchq/CyberChef · error · OperationError

Input cannot be empty.

Error message

Input cannot be empty.

What it means

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.

Source

Thrown at src/core/lib/Bech32.mjs:239

    // Check maximum length (90 characters)
    if (result.length > 90) {
        throw new OperationError(`Encoded string exceeds maximum length of 90 characters (got ${result.length}). Consider using smaller input data.`);
    }

    return result;
}

/**
 * Decode a Bech32/Bech32m string
 *
 * @param {string} str - Bech32/Bech32m encoded string
 * @param {string} encoding - "Bech32", "Bech32m", or "Auto-detect"
 * @returns {{hrp: string, data: number[]}} - Decoded HRP and data bytes
 */
export function decode(str, encoding = "Auto-detect") {
    // Check for empty input
    if (!str || str.length === 0) {
        throw new OperationError("Input cannot be empty.");
    }

    // Check maximum length
    if (str.length > 90) {
        throw new OperationError(`Invalid Bech32 string: exceeds maximum length of 90 characters (got ${str.length}).`);
    }

    // Check for mixed case
    const hasUpper = /[A-Z]/.test(str);
    const hasLower = /[a-z]/.test(str);
    if (hasUpper && hasLower) {
        throw new OperationError("Invalid Bech32 string: mixed case is not allowed. Use all uppercase or all lowercase.");
    }

    // Convert to lowercase for processing
    str = str.toLowerCase();

    // Find separator (last occurrence of '1')

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Check for a non-empty string before calling decode.
  2. Provide a clear user-facing error when the input is empty.
  3. Default the variable to '' only if you also short-circuit; better, require a value.
  4. Add a type guard: typeof str === 'string' && str.length > 0.

Example fix

// before
const result = decode(maybeUndefinedAddress);

// after
if (typeof maybeUndefinedAddress !== 'string' || maybeUndefinedAddress.length === 0) {
  throw new Error('A Bech32 address is required.');
}
const result = decode(maybeUndefinedAddress);
Defensive patterns

Strategy: validation

Validate before calling

function requireNonEmptyBech32(str) {
  if (typeof str !== 'string' || str.length === 0) {
    throw new TypeError('A non-empty Bech32 string is required.');
  }
  return str;
}

Type guard

function isNonEmptyString(s) {
  return typeof s === 'string' && s.length > 0;
}

Try / catch

try {
  decode(input);
} catch (e) {
  if (e instanceof OperationError && /Input cannot be empty/.test(e.message)) {
    // prompt the user for an address
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/214d77547a7c009e. Report an issue: GitHub.