{"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":407,"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":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/ac9a4e9abd8fd3058c070b72c23402a4f887929a/gitnexus/src/cli/analyze-config.ts#L389-L425","documentation":".gitnexusrc parsed as JSON but the top level is not an object: an array, a bare string/number/boolean, or null all fail the object check at analyze-config.ts:399. The rc file models key/value settings, so only a JSON object at the root is meaningful.","triggerScenarios":".gitnexusrc containing [] (common when scaffolding an 'empty' file), \"develop\", 42, true, or null at the top level.","commonSituations":"echo [] > .gitnexusrc as a placeholder; converting from a list-style config format; tools that emit a bare scalar for single-value configs.","solutions":["Make the root an object: {} at minimum, or {\"defaultBranch\": \"develop\"}","If you intended no config, delete the file entirely — absence is the supported 'no defaults' state","Lint the rc file in CI asserting typeof parsed === 'object' && !Array.isArray(parsed)"],"exampleFix":"// before (.gitnexusrc)\n[]\n// after\n{}","handlingStrategy":"validation","validationCode":"const rc = JSON.parse(raw);\nif (rc === null || typeof rc !== 'object' || Array.isArray(rc)) {\n  throw new Error('.gitnexusrc root must be a JSON object');\n}","typeGuard":"const isJsonObject = (v: unknown): v is Record<string, unknown> =>\n  v !== null && typeof v === 'object' && !Array.isArray(v);","tryCatchPattern":"catch (err) {\n  if (err instanceof GitNexusRcError && err.message.includes('must contain a JSON object')) {\n    // replace []/null/scalar with {} and add keys as needed\n  }\n}","preventionTips":["Never scaffold with echo [] > .gitnexusrc; use {} or no file","For 'no defaults', delete the file — absence is supported"],"tags":["config","json","validation","gitnexusrc"],"backgroundTag":"config-type-mismatch","analyzedSha":"ac9a4e9abd8fd3058c070b72c23402a4f887929a","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}