{"record":{"id":"636762ccb09617ee","repo":"gchq/CyberChef","slug":"this-name-cannot-be-empty","errorCode":null,"errorMessage":"${this.name} cannot be empty.","messagePattern":"(.+?) cannot be empty\\.","errorType":"validation","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/Ingredient.mjs","lineNumber":109,"sourceCode":"        }\n\n        // 1. check if empty\n        let isEmpty = false;\n        if (checkVal === null || checkVal === undefined || checkVal === \"\") {\n            isEmpty = true;\n        } else if (typeof checkVal.length === \"number\" && checkVal.length === 0) {\n            isEmpty = true;\n        }\n\n        if (isEmpty) {\n            let isAllowedOptionEmpty = false;\n            if (this.type === \"option\" && Array.isArray(this.defaultValue)) {\n                isAllowedOptionEmpty = this.defaultValue.includes(\"\");\n            } else if (this.type === \"argSelector\" && Array.isArray(this.defaultValue)) {\n                isAllowedOptionEmpty = this.defaultValue.some(opt => opt.name === \"\");\n            }\n            if (this.allowEmpty === false || ((this.type === \"option\" || this.type === \"argSelector\") && !isAllowedOptionEmpty)) {\n                throw new OperationError(`${this.name} cannot be empty.`);\n            }\n            return true;\n        }\n\n        // 2. maxLength check\n        if (typeof this.maxLength === \"number\" && checkVal !== null && checkVal !== undefined) {\n            if (typeof checkVal === \"string\" && checkVal.length > this.maxLength) {\n                throw new OperationError(`${this.name} length cannot exceed ${this.maxLength}.`);\n            }\n            if (Array.isArray(checkVal) && checkVal.length > this.maxLength) {\n                throw new OperationError(`${this.name} length cannot exceed ${this.maxLength}.`);\n            }\n            if (checkVal instanceof Uint8Array && checkVal.length > this.maxLength) {\n                throw new OperationError(`${this.name} length cannot exceed ${this.maxLength}.`);\n            }\n        }\n\n        // 3. number checks","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/Ingredient.mjs#L91-L127","documentation":"Thrown by Ingredient.validate() when the resolved checkVal is empty (null, undefined, '', or a value with .length === 0) AND the ingredient disallows empty: either allowEmpty was explicitly set false in the config, or the ingredient is type option/argSelector whose permitted set does not include ''. This is recipe-argument validation, enforced before an operation runs.","triggerScenarios":"An operation ingredient declared with allowEmpty:false receives '' from a recipe; a required text field left blank in the UI; an option/argSelector ingredient whose default list omits '' and the user supplies an empty selection.","commonSituations":"A recipe omits or blanks a required argument (e.g. a cipher key, IV, delimiter); copying a recipe that worked for one operation into another whose arg is non-empty; UI submitting an untouched required field.","solutions":["Supply a non-empty value for the named ingredient in the recipe/args array.","If empty is legitimately valid, set allowEmpty:true in the operation's ingList config for that ingredient.","For option/argSelector ingredients that should permit empty, include '' (or {name:''}) in the defaultValue list."],"exampleFix":"// before - ingredient config\n{ name: 'Key', type: 'string', value: '', allowEmpty: false }\n\n// after - either supply a value\nop.ingValues = ['mysecretkey']\n// or allow empty in config\n{ name: 'Key', type: 'string', value: '', allowEmpty: true }","handlingStrategy":"validation","validationCode":"function ensureNonEmpty(name, val, allowEmpty) {\n  const empty = val == null || val === '' || (typeof val.length === 'number' && val.length === 0);\n  if (empty && allowEmpty === false) throw new Error(`${name} must not be empty`);\n}\n// run before op.ingValues = [...]","typeGuard":"function isNonEmpty(v): v is string { return v != null && v !== '' && v.length > 0; }","tryCatchPattern":"try {\n  op.ingValues = values;\n} catch (e) {\n  if (e instanceof OperationError && /cannot be empty/.test(e.message)) {\n    // supply a value for the named ingredient\n  }\n}","preventionTips":["Always pass a concrete value for ingredients declared allowEmpty:false.","When authoring an operation, set allowEmpty only after confirming empty is acceptable.","For option/argSelector ingredients, include '' in the list if empty is valid."],"tags":["ingredient","validation","required-field","operationerror"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}