Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/build/resolveOpenAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {DeRefedOpenAPI} from './open-api/types';

// SENTRY_API_SCHEMA_SHA is used in the sentry-docs GHA workflow in getsentry/sentry-api-schema.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The resolveOpenAPI function doesn't check if the HTTP response is successful before parsing it as JSON, which can cause cryptic build failures.
Severity: HIGH

Suggested Fix

Before calling await response.json(), add a check for the HTTP response status. If !response.ok, throw a new error with a more informative message, including the status and status text, to clarify why the fetch failed. This will prevent cryptic JSON parsing errors and make debugging build failures easier. Example: if (!response.ok) { throw new Error(Failed to fetch OpenAPI schema: ${response.status} ${response.statusText}); }.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/build/resolveOpenAPI.ts#L9

Potential issue: The `resolveOpenAPI` function fetches an OpenAPI schema from a
`raw.githubusercontent.com` URL. It directly calls `response.json()` without first
verifying `response.ok`. If the requested file is unavailable (e.g., due to an invalid
commit SHA), GitHub will return a 404 response with an HTML body. The `fetch` API does
not treat this as an error, so the code proceeds to call `response.json()` on the HTML,
which throws a cryptic `SyntaxError`. Since this function is called during the build
process (`generateStaticParams`), this error will cause the entire site build to fail,
preventing deployment.

Did we get this right? 👍 / 👎 to inform future reviews.

// DO NOT change variable name unless you change it in the sentry-docs GHA workflow in getsentry/sentry-api-schema.
const SENTRY_API_SCHEMA_SHA = '0026719ede0a1ced5b9fc0b40a76b117becbc11b';
const SENTRY_API_SCHEMA_SHA = '3dd2b5de6fbb8023e4086054f771f1501ece8797';

const activeEnv = process.env.GATSBY_ENV || process.env.NODE_ENV || 'development';

Expand Down
Loading