{"record":{"id":"8fac045b3123fb7a","repo":"abhigyanpatwari/GitNexus","slug":"branch-must-be-a-string","errorCode":null,"errorMessage":"\"branch\" must be a string","messagePattern":"\"branch\" must be a string","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"gitnexus/src/server/api.ts","lineNumber":1752,"sourceCode":"        if (\n          asyncApiSpecPath !== undefined &&\n          (typeof asyncApiSpecPath !== 'string' || asyncApiSpecPath.trim().length === 0)\n        ) {\n          res.status(400).json({ error: '\"asyncApiSpecPath\" must be a non-empty string' });\n          return;\n        }\n\n        if (!repoUrl && !repoLocalPath) {\n          res.status(400).json({ error: 'Provide \"url\" (git URL) or \"path\" (local path)' });\n          return;\n        }\n\n        // Branch: optional index-branch selector, validated with the same rules\n        // as the CLI's `--branch` so both entry points accept the same refs.\n        // Rejecting here (rather than letting the clone fail) keeps a malformed\n        // ref from ever reaching `git`.\n        if (repoBranch !== undefined && typeof repoBranch !== 'string') {\n          res.status(400).json({ error: '\"branch\" must be a string' });\n          return;\n        }\n        let analyzeBranch: string | undefined;\n        if (repoBranch !== undefined) {\n          try {\n            analyzeBranch = validateBranchName(repoBranch, '\"branch\"');\n          } catch (err) {\n            if (err instanceof InvalidBranchError) {\n              res.status(400).json({ error: err.message });\n              return;\n            }\n            throw err;\n          }\n        }\n\n        // Token: optional, restricted charset to prevent header smuggling\n        // (CRLF), bound length, and bound to github.com (see validateAnalyzeToken).\n        const tokenError = validateAnalyzeToken(repoToken, repoUrl);","sourceCodeStart":1734,"sourceCodeEnd":1770,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/ac9a4e9abd8fd3058c070b72c23402a4f887929a/gitnexus/src/server/api.ts#L1734-L1770","documentation":"A 400 validation response from the analyze endpoint: the optional `branch` field in the request body must be a string (an index-branch selector validated like the CLI's --branch flag). The server rejects non-string values before the ref can reach git.","triggerScenarios":"POST to the analyze route with body { branch: 123 }, { branch: true }, { branch: null } (treated as non-undefined), or any other non-string type.","commonSituations":"Happens when clients build the JSON body dynamically (e.g. number-like branch names '123' parsed as numbers by YAML/JSON tooling), or a template sends a null placeholder instead of omitting the field.","solutions":["Send branch as a JSON string: { \"branch\": \"main\" }","Omit the branch field entirely instead of sending null","Quote numeric-looking branch names in your request-building code or config","Use the same branch value that works with the CLI's --branch flag"],"exampleFix":"// before\n{ \"repo\": \"my-repo\", \"branch\": 123 }\n// 400 { error: '\"branch\" must be a string' }\n\n// after\n{ \"repo\": \"my-repo\", \"branch\": \"123-release\" }","handlingStrategy":"validation","validationCode":"const isBranchOk = typeof branch === 'string' && branch.length > 0;\nif (branch !== undefined && !isBranchOk) throw new Error('branch must be a string');","typeGuard":"const isString = (v: unknown): v is string => typeof v === 'string';\nif (branch !== undefined && !isString(branch)) throw new TypeError('\"branch\" must be a string');","tryCatchPattern":null,"preventionTips":["Quote numeric-looking branch names when building requests from configs/YAML","Omit branch instead of sending null or placeholders","Type-check request bodies at the boundary (zod/ajv schema with branch: string optional)"],"tags":["http-400","validation","type-mismatch","branch"],"backgroundTag":"type-mismatch","analyzedSha":"ac9a4e9abd8fd3058c070b72c23402a4f887929a","analyzedAt":"2026-09-15T23:29:44.066Z","contentChangedAt":"2026-09-15T23:29:44.066Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}