mastra-ai/mastra · error
GitHub ${resource} id must be a positive integer.
Error message
GitHub ${resource} id must be a positive integer. What it means
requirePositiveId validates that a GitHub resource identifier (pull request or issue number) extracted from a source id string is a valid positive integer. Non-numeric, zero, negative, or decimal values are rejected because GitHub PR/issue numbers are positive integers.
Source
Thrown at mastracode/factory/src/integrations/github/integration.ts:1474
if (state === 'APPROVED') return 'approved';
if (state === 'CHANGES_REQUESTED') return 'changes-requested';
if (state === 'DISMISSED') return 'dismissed';
throw new Error(`Unsupported GitHub review state: ${state}`);
}
function reviewEventToGithub(event: Exclude<InputOf<'createReview'>['event'], undefined>) {
if (event === 'approve') return 'APPROVE' as const;
if (event === 'request-changes') return 'REQUEST_CHANGES' as const;
return 'COMMENT' as const;
}
function requirePullRequestNumber(value: string): number {
return requirePositiveId(value, 'pull request');
}
function requirePositiveId(value: string, resource: string): number {
const parsed = parsePositiveInteger(value);
if (parsed === null) throw new Error(`GitHub ${resource} id must be a positive integer.`);
return parsed;
}
function getGithubInstallationId(connection: IntegrationConnection): number {
if (connection.type !== 'app-installation') {
throw new Error('GitHub capabilities require an app-installation connection.');
}
return connection.installationId;
}
function getSingleSourceId(sourceIds: string[], message: string): string {
if (sourceIds.length !== 1) throw new Error(message);
return sourceIds[0]!;
}
function normalizeLabels(labels: string[] | undefined): string[] {
return [...new Set((labels ?? []).map(label => label.trim()).filter(Boolean))];
}View on GitHub (pinned to 75dd419e61)
Solutions
- Pass the bare numeric string, e.g. '42'.
- Strip non-digit prefixes with a regex like /\d+$/ before calling.
- Check upstream code that builds the source id for concatenation bugs.
- Log the raw value to see what is actually being passed.
Example fix
// before
requirePullRequestNumber('pr-42');
// after
requirePullRequestNumber('42'); Defensive patterns
Strategy: validation
Validate before calling
const n = Number(value);
if (!Number.isInteger(n) || n <= 0) throw new Error(`invalid GitHub id: ${value}`); Type guard
function isPositiveIntegerString(v: unknown): v is string {
return typeof v === 'string' && /^\d+$/.test(v) && Number(v) > 0;
} Try / catch
try {
const num = requirePullRequestNumber(id);
} catch {
const m = id.match(/\d+$/);
if (!m) throw new Error(`cannot derive PR number from: ${id}`);
return useNumber(Number(m[0]));
} Prevention
- Store PR/issue numbers as bare integer strings or numbers.
- Strip URL prefixes before extracting ids.
- Avoid Number() on user input without integer validation.
When it happens
Trigger: Passing sourceIds like 'pr-42', '0', '-1', '12.5', or an empty string into capabilities that call requirePullRequestNumber/requirePositiveId.
Common situations: Prefixing ids with a resource label; storing ids as floats; pulling a number from a URL that still contains text; locale formatting adding separators.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- GitHub pull requests require an owner/repository source.
- A review comment requires commitId, path, line, and side unl
- A multi-line review comment requires both startLine and star
- GitHub triage comments require an owner/repository source.
- ${message}
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/cf3082d074d3d2ed.
Report an issue: GitHub.