toeverything/AFFiNE · error · Error

A config file path is required

Error message

A config file path is required

What it means

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.

Source

Thrown at packages/backend/server/src/data/commands/import.ts:20

import { resolve } from 'node:path';

import { Injectable, Logger } from '@nestjs/common';

import { ConfigFactory, InvalidAppConfigInput } from '../../base';
import { Models } from '../../models';

@Injectable()
export class ImportConfigCommand {
  logger = new Logger(ImportConfigCommand.name);

  constructor(
    private readonly models: Models,
    private readonly configFactory: ConfigFactory
  ) {}

  async execute(path?: string): Promise<void> {
    if (!path) {
      throw new Error('A config file path is required');
    }

    path = resolve(process.cwd(), path);

    const overrides: Record<string, Record<string, any>> = JSON.parse(
      readFileSync(path, 'utf-8')
    );

    const forValidation: { module: string; key: string; value: any }[] = [];
    const forSaving: { key: string; value: any }[] = [];
    Object.entries(overrides).forEach(([module, config]) => {
      if (module === '$schema') {
        return;
      }

      Object.entries(config).forEach(([key, value]) => {
        forValidation.push({
          module,

View on GitHub (pinned to 26c515e050)

Solutions

  1. Pass the config file path as the first argument: `import-config ./config/overrides.json`.
  2. If the path comes from an env var, default it or fail fast with a clear message before invoking the command.
  3. In wrapper scripts, guard `if [ -z "$CONFIG" ]; then echo usage; exit 1; fi` before the call.
  4. Ensure the argument is not being swallowed by an upstream flag parser.

Example fix

// before
await importConfig.execute();

// after
const file = process.env.IMPORT_CONFIG_PATH;
if (!file) {
  console.error('Usage: import-config <path-to-json>');
  process.exit(1);
}
await importConfig.execute(file);
Defensive patterns

Strategy: validation

Validate before calling

const file = process.env.IMPORT_CONFIG_PATH;
if (!file) {
  console.error('Usage: import-config <path-to-json>');
  process.exit(1);
}
await importConfig.execute(file);

Type guard

function hasConfigPath(path) {
  return typeof path === 'string' && path.length > 0;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of toeverything/AFFiNE@26c515e050 (2026-08-12). Data as JSON: /api/errors/4b20e1354db5a1cd. Report an issue: GitHub.