{"record":{"id":"4b20e1354db5a1cd","repo":"toeverything/AFFiNE","slug":"a-config-file-path-is-required","errorCode":null,"errorMessage":"A config file path is required","messagePattern":"A config file path is required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/backend/server/src/data/commands/import.ts","lineNumber":20,"sourceCode":"import { resolve } from 'node:path';\n\nimport { Injectable, Logger } from '@nestjs/common';\n\nimport { ConfigFactory, InvalidAppConfigInput } from '../../base';\nimport { Models } from '../../models';\n\n@Injectable()\nexport class ImportConfigCommand {\n  logger = new Logger(ImportConfigCommand.name);\n\n  constructor(\n    private readonly models: Models,\n    private readonly configFactory: ConfigFactory\n  ) {}\n\n  async execute(path?: string): Promise<void> {\n    if (!path) {\n      throw new Error('A config file path is required');\n    }\n\n    path = resolve(process.cwd(), path);\n\n    const overrides: Record<string, Record<string, any>> = JSON.parse(\n      readFileSync(path, 'utf-8')\n    );\n\n    const forValidation: { module: string; key: string; value: any }[] = [];\n    const forSaving: { key: string; value: any }[] = [];\n    Object.entries(overrides).forEach(([module, config]) => {\n      if (module === '$schema') {\n        return;\n      }\n\n      Object.entries(config).forEach(([key, value]) => {\n        forValidation.push({\n          module,","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/26c515e050211269e911f7d9cfe162a26c83ed98/packages/backend/server/src/data/commands/import.ts#L2-L38","documentation":"Thrown by `ImportConfigCommand.execute` when the `path` argument is falsy — the CLI was invoked without supplying a config file path. This is a plain `Error` (no error code), so it surfaces as a generic internal/CLI error rather than a user-friendly typed error.","triggerScenarios":"Running the import-config CLI command with no argument, an empty string, or `undefined`. E.g. `import-config` instead of `import-config ./overrides.json`, or a wrapper script that failed to interpolate the path variable.","commonSituations":"Misconfigured shell script or CI step that forgets the path argument; env var for the path unset (`import-config \"$CONFIG_FILE\"` with `CONFIG_FILE` empty); typo in the command definition that drops the argument.","solutions":["Pass the config file path as the first argument: `import-config ./config/overrides.json`.","If the path comes from an env var, default it or fail fast with a clear message before invoking the command.","In wrapper scripts, guard `if [ -z \"$CONFIG\" ]; then echo usage; exit 1; fi` before the call.","Ensure the argument is not being swallowed by an upstream flag parser."],"exampleFix":"// before\nawait importConfig.execute();\n\n// after\nconst file = process.env.IMPORT_CONFIG_PATH;\nif (!file) {\n  console.error('Usage: import-config <path-to-json>');\n  process.exit(1);\n}\nawait importConfig.execute(file);","handlingStrategy":"validation","validationCode":"const file = process.env.IMPORT_CONFIG_PATH;\nif (!file) {\n  console.error('Usage: import-config <path-to-json>');\n  process.exit(1);\n}\nawait importConfig.execute(file);","typeGuard":"function hasConfigPath(path) {\n  return typeof path === 'string' && path.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Always pass the config file path as the first CLI argument.","Default or validate the env var before invoking the command.","Add a usage guard in wrapper scripts before the call."],"tags":["cli","config","import","nestjs","validation"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}