{"record":{"id":"9b09f6e23423c14f","repo":"linshenkx/prompt-optimizer","slug":"predefined-variable-override","errorCode":"PREDEFINED_VARIABLE_OVERRIDE","errorMessage":"Cannot override predefined variable: ${name}","messagePattern":"Cannot override predefined variable: (.+?)","errorType":"validation","errorClass":"VariableError","httpStatus":null,"severity":"error","filePath":"packages/ui/src/services/VariableManager.ts","lineNumber":121,"sourceCode":"            return 'Name cannot start with a number.'\n          case 'reservedName':\n            return 'Name is reserved.'\n          case 'invalidCharacters':\n            return 'Name cannot contain whitespace or braces ({}).' \n          default:\n            return 'Name is invalid.'\n        }\n      })()\n      throw new VariableError(\n        `Invalid variable name: ${name}. ${reasonText}`,\n        name,\n        undefined,\n        'INVALID_VARIABLE_NAME'\n      );\n    }\n\n    if (this.isPredefinedVariable(name)) {\n      throw new VariableError(\n        `Cannot override predefined variable: ${name}`,\n        name,\n        undefined,\n        'PREDEFINED_VARIABLE_OVERRIDE'\n      );\n    }\n\n    if (value.length > VARIABLE_VALIDATION.MAX_VALUE_LENGTH) {\n      throw new VariableError(\n        `Variable value too long: ${value.length} > ${VARIABLE_VALIDATION.MAX_VALUE_LENGTH}`,\n        name,\n        undefined,\n        'VALUE_TOO_LONG'\n      );\n    }\n\n    this.customVariables[name] = value;\n    this.saveToStorage();","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/ui/src/services/VariableManager.ts#L103-L139","documentation":"VariableManager.setVariable throws VariableError with code PREDEFINED_VARIABLE_OVERRIDE when a caller attempts to set a variable whose name matches one of the manager's predefined (built-in) variables. Predefined variables are reserved by the system and cannot be overwritten through the public API. The check is performed by isPredefinedVariable(name) before any mutation occurs.","triggerScenarios":"Calling setVariable(name, value) where name is in the predefined variable set (e.g. system-provided names registered at construction). Custom user variables are unaffected; only names colliding with predefined ones trigger this.","commonSituations":"User-supplied variable names forwarded directly to setVariable; migration/import tooling that re-registers all variables including built-ins; frontend forms that don't filter out predefined names from the editable list.","solutions":["Filter out predefined variables before calling setVariable (expose/use a listPredefinedVariables or isPredefinedVariable check)","Namespace user-created variables (e.g. prefix 'user.') to avoid collisions","If the value genuinely needs updating, use a custom variable name instead of the predefined one"],"exampleFix":"// before\nvariableManager.setVariable('APP_NAME', 'My App') // APP_NAME is predefined\n\n// after\nif (!variableManager.isPredefinedVariable('APP_NAME')) {\n  variableManager.setVariable('APP_NAME', 'My App')\n} else {\n  variableManager.setVariable('user.appName', 'My App')\n}","handlingStrategy":"validation","validationCode":"if (variableManager.isPredefinedVariable(name)) {\n  // skip, rename, or warn — do not call setVariable\n}","typeGuard":"const isSafeVariableName = (vm: VariableManager, name: string): boolean =>\n  !vm.isPredefinedVariable(name)","tryCatchPattern":"try {\n  vm.setVariable(name, value)\n} catch (e) {\n  if (e instanceof VariableError && e.code === 'PREDEFINED_VARIABLE_OVERRIDE') return\n  throw e\n}","preventionTips":["Prefix user-created variable names with a namespace like 'user.'","Filter predefined names out of editable variable lists in the UI"],"tags":["variables","predefined","validation"],"backgroundTag":"reserved-name-collision","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}