{"record":{"id":"e052299846b43b00","repo":"mastra-ai/mastra","slug":"message","errorCode":null,"errorMessage":"${message}","messagePattern":"\\$\\{message\\}","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/integrations/github/integration.ts","lineNumber":1486,"sourceCode":"function requirePullRequestNumber(value: string): number {\n  return requirePositiveId(value, 'pull request');\n}\n\nfunction requirePositiveId(value: string, resource: string): number {\n  const parsed = parsePositiveInteger(value);\n  if (parsed === null) throw new Error(`GitHub ${resource} id must be a positive integer.`);\n  return parsed;\n}\n\nfunction getGithubInstallationId(connection: IntegrationConnection): number {\n  if (connection.type !== 'app-installation') {\n    throw new Error('GitHub capabilities require an app-installation connection.');\n  }\n  return connection.installationId;\n}\n\nfunction getSingleSourceId(sourceIds: string[], message: string): string {\n  if (sourceIds.length !== 1) throw new Error(message);\n  return sourceIds[0]!;\n}\n\nfunction normalizeLabels(labels: string[] | undefined): string[] {\n  return [...new Set((labels ?? []).map(label => label.trim()).filter(Boolean))];\n}\n\nfunction requireSourceId(sourceId: string | undefined, message: string): string {\n  if (!sourceId) throw new Error(message);\n  return sourceId;\n}\n\nfunction parsePositiveCursor(cursor: string | undefined): number {\n  if (cursor === undefined) return 1;\n  const page = parsePositiveInteger(cursor);\n  if (page === null) throw new Error('GitHub cursor must be a positive page number.');\n  return page;\n}","sourceCodeStart":1468,"sourceCodeEnd":1504,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/integrations/github/integration.ts#L1468-L1504","documentation":"getSingleSourceId enforces that sourceIds contains exactly one element and returns it; otherwise it rethrows the caller-supplied message. Callers pass messages like 'expects exactly one source id', so the error text is capability-specific. It guards against ambiguous multi-source or empty inputs.","triggerScenarios":"Calling a capability scoped to one repository/PR with an empty sourceIds array or with multiple ids, e.g. sourceIds: [] or ['acme/a','acme/b'].","commonSituations":"Passing all selected sources instead of a single one; upstream filter returning zero matches; UI sending bulk selection to a single-item API.","solutions":["Ensure exactly one source id is passed for single-source capabilities.","Check the caller that builds sourceIds for empty/multi-element selections.","Split bulk work into per-source calls.","Inspect the error message text — it names which capability required a single source."],"exampleFix":"// before\nawait cap.run({ sourceIds: selected }); // may be 0 or many\n// after\nif (selected.length !== 1) throw new Error('select exactly one repository');\nawait cap.run({ sourceIds: [selected[0]] });","handlingStrategy":"validation","validationCode":"if (!Array.isArray(sourceIds) || sourceIds.length !== 1 || !sourceIds[0]) throw new Error('exactly one source id required');","typeGuard":"function isSingleSourceId(v: unknown): v is [string] {\n  return Array.isArray(v) && v.length === 1 && typeof v[0] === 'string' && v[0].length > 0;\n}","tryCatchPattern":"try {\n  await runCapability({ sourceIds });\n} catch (e) {\n  if ((e as Error).message.includes('exactly one')) throw new Error(`got ${sourceIds?.length ?? 0} sources, need exactly 1`);\n  throw e;\n}","preventionTips":["Validate selection cardinality in the caller/UI before invoking.","Handle empty filter results upstream instead of passing [].","Loop per-source for bulk operations instead of passing arrays."],"tags":["github","validation","input"],"backgroundTag":"invalid-argument-count","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}