Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix downloads: Filter out invalid releases #5923

Merged
merged 1 commit into from
Jan 10, 2025
Merged

Fix downloads: Filter out invalid releases #5923

merged 1 commit into from
Jan 10, 2025

Conversation

estib-vega
Copy link
Contributor

Parse and guard the response from the releases API to ensure the input is the one expected.

Copy link

vercel bot commented Jan 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
gitbutler-components ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 10, 2025 2:44pm
gitbutler-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 10, 2025 2:44pm

@estib-vega
Copy link
Contributor Author

The processBuilds function was expecting an array of objects of type Build, which in the case of one build, it seemed to not completely match.

This is fixed now in that we'll probe the result out and filter out whatever doesn't match the output

@estib-vega estib-vega force-pushed the e-branch-1 branch 2 times, most recently from fab49a1 to 14433d3 Compare January 10, 2025 14:31
Comment on lines 46 to 65
export function getValidReleases(something: unknown): Release[] {
if (!Array.isArray(something)) return [];
const result: Release[] = [];
for (const item of something) {
if (isRelease(item)) {
result.push(item);
continue;
}

// TODO: Add some metrics to this
console.warn('Invalid release:', item);
}
return result;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be reporting this to Sentry?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO yeah, do we already do that anywhere in the app? I'll look for an example of that

Comment on lines +31 to +46
export function isRelease(something: unknown): something is Release {
return (
typeof something === 'object' &&
something !== null &&
typeof (something as any).version === 'string' &&
(typeof (something as any).notes === 'string' || (something as any).notes === null) &&
typeof (something as any).sha === 'string' &&
typeof (something as any).channel === 'string' &&
typeof (something as any).build_version === 'string' &&
typeof (something as any).released_at === 'string' &&
Array.isArray((something as any).builds) &&
(something as any).builds.every(isReleaseBuild)
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it time for zod?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would love that

Copy link
Contributor

@Caleb-T-Owens Caleb-T-Owens left a comment

Choose a reason for hiding this comment

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

Happy for this to be shipped and to consider zods and sentrees later

Parse and guard the response from the releases API to ensure the input is the one expected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants