-
Notifications
You must be signed in to change notification settings - Fork 558
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
The This is fixed now in that we'll probe the result out and filter out whatever doesn't match the output |
fab49a1
to
14433d3
Compare
apps/web/src/lib/types/releases.ts
Outdated
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; | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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) | ||
); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love that
There was a problem hiding this 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.
14433d3
to
3b66859
Compare
3b66859
to
61b185e
Compare
Parse and guard the response from the releases API to ensure the input is the one expected.