{"record":{"id":"de0acd38461633f1","repo":"zitadel/zitadel","slug":"value-must-not-be-empty","errorCode":null,"errorMessage":"value must not be empty","messagePattern":"value must not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/actions/object/metadata.go","lineNumber":190,"sourceCode":"\t\t\tKey:   call.Arguments[0].Export().(string),\n\t\t\tValue: call.Arguments[1],\n\t\t\tvalue: value,\n\t\t})\n\treturn nil\n}\n\n// AppendMetadataRawFunc appends a metadata entry storing the value as raw bytes\n// without JSON encoding. In contrast to [MetadataList.AppendMetadataFunc], a string\n// is stored as its plain UTF-8 bytes (e.g. `de` instead of `\"de\"`).\n// Allowed values are strings and byte arrays (Uint8Array or an array of integers 0-255).\nfunc (md *MetadataList) AppendMetadataRawFunc(call goja.FunctionCall) goja.Value {\n\tif len(call.Arguments) != 2 {\n\t\tpanic(\"exactly 2 (key, value) arguments expected\")\n\t}\n\n\tvalue := rawMetadataValue(call.Arguments[1].Export())\n\tif len(value) == 0 {\n\t\tpanic(\"value must not be empty\")\n\t}\n\n\tmd.metadata = append(md.metadata,\n\t\t&Metadata{\n\t\t\tKey:   call.Arguments[0].Export().(string),\n\t\t\tValue: call.Arguments[1],\n\t\t\tvalue: value,\n\t\t})\n\treturn nil\n}\n\n// rawMetadataValue converts an exported goja value to raw bytes.\n// Strings are converted to their UTF-8 bytes, Uint8Array is exported as []byte directly\n// and plain arrays must only contain integers in the range 0-255.\nfunc rawMetadataValue(v interface{}) []byte {\n\tswitch value := v.(type) {\n\tcase string:\n\t\treturn []byte(value)","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/zitadel/zitadel/blob/13948f2bcd6f257794dbd6d342c2ac30bc88fe54/internal/actions/object/metadata.go#L172-L208","documentation":"Guard panic in the actions JS runtime: AppendMetadataRawFunc was called with an empty (or otherwise unsupported) raw metadata value. Only strings and byte arrays (Uint8Array / 0-255 integer arrays) are accepted as raw values, and the value must not be empty.","triggerScenarios":"A JS action calls appendMetadataRaw(key, '') with an empty string, or with an empty array / array of values that normalize to zero bytes.","commonSituations":"Dynamic value built from an empty variable; translation/localization lookup returning empty string; script passing undefined which exports to an empty raw value.","solutions":["Pass a non-empty string or a byte array with at least one element","Check the source variable in the action for empty/undefined values before calling","Remove the metadata entry instead of setting an empty value if that was the intent"],"exampleFix":"// before\nconst lang = i18n.detect(); // may be ''\nmetadata.appendMetadataRaw('lang', lang);\n// after\nif (lang) { metadata.appendMetadataRaw('lang', lang); }","handlingStrategy":"validation","validationCode":"if (!value || (Array.isArray(value) && value.length === 0)) throw new Error('metadata value required');","typeGuard":"function isNonEmptyRawValue(v){ return (typeof v === 'string' && v.length > 0) || (Array.isArray(v) && v.length > 0); }","tryCatchPattern":"try { metadata.appendMetadataRaw(key, value); } catch (e) { if (/empty/.test(String(e))) { value = fallbackValue; metadata.appendMetadataRaw(key, value); } }","preventionTips":["Check source variables for empty/undefined before appending","Delete metadata entries instead of writing empty values","Add action unit tests covering empty-value paths"],"tags":["actions","javascript","metadata","validation"],"backgroundTag":"empty-required-field","analyzedSha":"13948f2bcd6f257794dbd6d342c2ac30bc88fe54","analyzedAt":"2026-09-06T10:16:19.814Z","contentChangedAt":"2026-09-06T10:16:19.814Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}