{"record":{"id":"7a2c2856117c9347","repo":"abhigyanpatwari/GitNexus","slug":"gitnexus-rc-filename-must-contain-a-json-object","errorCode":null,"errorMessage":"${GITNEXUS_RC_FILENAME} must contain a JSON object.","messagePattern":"(.+?) must contain a JSON object\\.","errorType":"validation","errorClass":"GitNexusRcError","httpStatus":null,"severity":"error","filePath":"gitnexus/src/cli/analyze-config.ts","lineNumber":399,"sourceCode":"\n  // Strip a leading UTF-8 BOM: Node's 'utf-8' decode keeps it, and JSON.parse\n  // then fails with a confusing \"Unexpected token\" on an otherwise-valid file\n  // (#1996 tri-review). Only one leading BOM is stripped; in-string control\n  // rejection still applies to the parsed values.\n  if (raw.charCodeAt(0) === 0xfeff) raw = raw.slice(1);\n\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(raw);\n  } catch (err) {\n    throw new GitNexusRcError(\n      `${GITNEXUS_RC_FILENAME} is not valid JSON: ${(err as Error).message}. ` +\n        `Expected a JSON object such as {\"defaultBranch\": \"develop\", \"skipContextFiles\": true}.`,\n    );\n  }\n\n  if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {\n    throw new GitNexusRcError(`${GITNEXUS_RC_FILENAME} must contain a JSON object.`);\n  }\n\n  const obj = parsed as Record<string, unknown>;\n  const flat = normalizeLevel(obj, { allowNestedKey: true });\n\n  let nested: Partial<AnalyzeOptions> = {};\n  if (Object.prototype.hasOwnProperty.call(obj, NESTED_KEY)) {\n    const nestedRaw = obj[NESTED_KEY];\n    if (nestedRaw === null || typeof nestedRaw !== 'object' || Array.isArray(nestedRaw)) {\n      throw new GitNexusRcError(`${GITNEXUS_RC_FILENAME} \"${NESTED_KEY}\" must be a JSON object.`);\n    }\n    nested = normalizeLevel(nestedRaw as Record<string, unknown>, { allowNestedKey: false });\n  }\n\n  // Nested `analyze` block overrides flat top-level keys for the same option.\n  return { ...flat, ...nested };\n}\n","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/gitnexus/src/cli/analyze-config.ts#L381-L417","documentation":"`.gitnexusrc` parsed as valid JSON, but the top-level value is not a JSON object — it is an array, a bare string/number/boolean, or null. GitNexus requires a top-level object (flat keys and/or a nested `analyze` block).","triggerScenarios":"File contents [], [\"defaultBranch\", \"develop\"], \"develop\", 42, or null.","commonSituations":"Treating `.gitnexusrc` as a list of strings; leftover scratch content written into the file; a generator that emits an array instead of an object.","solutions":["Wrap the content in a JSON object with the documented key names.","If the file was scratch, replace it with a valid object or delete it."],"exampleFix":"// before\n[\"defaultBranch\", \"develop\"]\n// after\n{\"defaultBranch\": \"develop\"}","handlingStrategy":"validation","validationCode":"const parsed = JSON.parse(raw);\nif (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {\n  throw new Error('.gitnexusrc must contain a JSON object');\n}","typeGuard":"const isPlainObject = (v) =>\n  v !== null && typeof v === 'object' && !Array.isArray(v);","tryCatchPattern":null,"preventionTips":["Always wrap .gitnexusrc content in { ... }.","Do not store lists or bare scalars at the top level."],"tags":["config","gitnexusrc","json","validation"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}