{"record":{"id":"2057aaa9b21aa222","repo":"ruvnet/ruflo","slug":"invalid-json-in-import-file-resolved","errorCode":null,"errorMessage":"Invalid JSON in import file: ${resolved}","messagePattern":"Invalid JSON in import file: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/services/config-file-manager.ts","lineNumber":161,"sourceCode":"  /** Export config to a specific path */\n  exportTo(cwd: string, exportPath: string): void {\n    const config = this.getConfig(cwd);\n    const resolved = path.resolve(cwd, exportPath);\n    this.writeAtomic(resolved, config);\n  }\n\n  /** Import config from a specific path */\n  importFrom(cwd: string, importPath: string): void {\n    const resolved = path.resolve(cwd, importPath);\n    if (!fs.existsSync(resolved)) {\n      throw new Error(`Import file not found: ${resolved}`);\n    }\n    const content = fs.readFileSync(resolved, 'utf-8');\n    let imported: Record<string, unknown>;\n    try {\n      imported = JSON.parse(content);\n    } catch {\n      throw new Error(`Invalid JSON in import file: ${resolved}`);\n    }\n    if (typeof imported !== 'object' || imported === null || Array.isArray(imported)) {\n      throw new Error('Import file must contain a JSON object');\n    }\n    const targetPath = this.configPath ?? path.resolve(cwd, CONFIG_FILENAMES[0]);\n    this.writeAtomic(targetPath, imported);\n    this.config = imported;\n    this.configPath = targetPath;\n  }\n\n  /** Get the path to the current config file */\n  getConfigPath(): string | null {\n    return this.configPath;\n  }\n\n  /** Get default config */\n  getDefaults(): Record<string, unknown> {\n    return { ...DEFAULT_CONFIG };","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/services/config-file-manager.ts#L143-L179","documentation":"ConfigFileManager.importFrom reads the import file, then JSON.parse is attempted inside a try/catch; if parsing throws, the file exists but is not valid JSON. This is a content-validity error distinct from the missing-file error.","triggerScenarios":"The resolved import file contains malformed JSON: trailing commas, unquoted keys, single-quoted strings, a BOM/encoding issue, a partially written file, or JSON5/JSONC syntax that JSON.parse rejects.","commonSituations":"Importing a hand-edited file with comments (JSONC) or trailing commas; a previous atomic write was interrupted leaving truncated JSON; the file is actually YAML/TOML mislabeled .json; encoding is UTF-16 with BOM.","solutions":["Validate the file with a JSON linter or JSON.parse(fs.readFileSync(p,'utf-8')) before calling importFrom.","Strip JSONC comments / trailing commas from the source, or convert it to strict JSON.","Re-export a known-good config from another project and import that.","Ensure the file is UTF-8 without BOM."],"exampleFix":"// before\nmanager.importFrom(cwd, './config.json'); // throws 'Invalid JSON'\n\n// after — pre-validate and surface a clearer error\nconst raw = fs.readFileSync(path.resolve(cwd, './config.json'), 'utf-8');\nlet parsed: unknown;\ntry { parsed = JSON.parse(raw); }\ncatch (e) { throw new Error(`config.json is not valid JSON: ${(e as Error).message}`); }\nmanager.importFrom(cwd, './config.json');","handlingStrategy":"validation","validationCode":"const resolved = path.resolve(cwd, importPath);\nconst raw = fs.readFileSync(resolved, 'utf-8');\nJSON.parse(raw); // throws here with a clearer context if invalid\nmanager.importFrom(cwd, importPath);","typeGuard":null,"tryCatchPattern":"try {\n  manager.importFrom(cwd, importPath);\n} catch (e) {\n  if ((e as Error).message.startsWith('Invalid JSON')) {\n    // surface file path + offer to re-export a known-good config\n  } else throw e;\n}","preventionTips":["Validate import files with a JSON linter before importing.","Keep config files strict JSON (no comments, no trailing commas).","Write configs via exportTo/atomic writes rather than hand-editing.","Ensure UTF-8 encoding without BOM."],"tags":["config","json","typescript"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}