{"record":{"id":"f2816bb3604ff152","repo":"immich-app/immich","slug":"error-instanceof-error-error-message-error","errorCode":null,"errorMessage":"error instanceof Error ? error.message : error","messagePattern":"error instanceof Error \\? error\\.message : error","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"server/src/services/system-config.service.ts","lineNumber":96,"sourceCode":"    const { logLevel } = this.configRepository.getEnv();\n    if (logLevel && !isEqual(toPlainObject(newConfig.logging), oldConfig.logging)) {\n      throw new Error('Logging cannot be changed while the environment variable IMMICH_LOG_LEVEL is set.');\n    }\n  }\n\n  async updateAdminConfig(dto: AdminConfigDto): Promise<AdminConfigDto> {\n    const { configFile } = this.configRepository.getEnv();\n    if (configFile) {\n      throw new BadRequestException('Cannot update configuration while IMMICH_CONFIG_FILE is in use');\n    }\n\n    const oldConfig = await this.getConfig({ withCache: false });\n\n    try {\n      await this.eventRepository.emit('ConfigValidate', { newConfig: toPlainObject(dto), oldConfig });\n    } catch (error) {\n      this.logger.warn(`Unable to save system config due to a validation error: ${error}`);\n      throw new BadRequestException(error instanceof Error ? error.message : error);\n    }\n\n    const newConfig = await this.updateConfig(dto);\n\n    await this.eventRepository.emit('ConfigUpdate', { newConfig, oldConfig });\n\n    return mapAdminConfig(newConfig);\n  }\n\n  async getCustomCss(): Promise<string> {\n    const { theme } = await this.getConfig({ withCache: false });\n    return theme.customCss;\n  }\n}\n","sourceCodeStart":78,"sourceCodeEnd":111,"githubUrl":"https://github.com/immich-app/immich/blob/e55ac299a4ec7cb372e35dbf2c6c05ee9ce77f6c/server/src/services/system-config.service.ts#L78-L111","documentation":"When the ConfigValidate event listeners (e.g. onConfigValidate) reject the new admin config, updateAdminConfig catches the error, logs a warning, and rethrows the validation message as a BadRequestException so the client sees the reason the config was not saved.","triggerScenarios":"Admin submits a system config that fails a ConfigValidate listener: e.g. changing logging while IMMICH_LOG_LEVEL is set, or any other listener-registered validation rule failing.","commonSituations":"Admin UI config save rejected due to env-var conflicts or invalid combinations; bulk config import containing sections that conflict with the environment.","solutions":["Read the validation message in the response and fix the offending config section accordingly","Check server logs for the 'Unable to save system config' warning with the underlying error","Resubmit the config with the conflicting section reverted to its previous value"],"exampleFix":"// before\ncatch (error) { throw error }\n// after (server behavior)\ncatch (error) {\n  logger.warn(`Unable to save system config: ${error}`);\n  throw new BadRequestException(error instanceof Error ? error.message : error);\n}\n// client: surface the message and correct the config","handlingStrategy":"try-catch","validationCode":"// client-side: validate config against known rules before submit\nif (process.env.IMMICH_LOG_LEVEL && changedSections.includes('logging')) {\n  alert('Logging changes are blocked while IMMICH_LOG_LEVEL is set');\n}","typeGuard":"null","tryCatchPattern":"try {\n  await api.saveAdminConfig(dto);\n} catch (e) {\n  if (e.status === 400) {\n    // e.message carries the listener validation error; show it to the user\n    showValidationError(e.message);\n  }\n}","preventionTips":["Read the BadRequest message — it contains the exact validation reason","Check server logs for 'Unable to save system config' warnings","Validate config against env-var constraints before submission"],"tags":["config","validation","bad-request","admin"],"backgroundTag":"schema-validation-failed","analyzedSha":"e55ac299a4ec7cb372e35dbf2c6c05ee9ce77f6c","analyzedAt":"2026-09-15T07:20:19.675Z","contentChangedAt":"2026-09-15T07:20:19.675Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}