-
Notifications
You must be signed in to change notification settings - Fork 193
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
Add error handling for when the profile file yaml parsing fails #1523
Conversation
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.
Looks pretty good but can be made more bullet proof with small changes.
try { | ||
this.profileImportContent = await ProfileUtils.parseYamlToExportFormat(read); | ||
} catch (e: unknown) { | ||
if(e instanceof R2Error) { |
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.
Well probably want to catch all errors here, including the once possibly thrown by yaml.parse
or any future additions to the helper function. So I would recommend skipping the if
check and just using R2Error.fromThrownValue
.
src/utils/ProfileUtils.ts
Outdated
'Ensure that the profile import file isn\'t corrupted.' | ||
) | ||
} | ||
if (!parsedYaml.profileName || typeof parsedYaml.profileName !== 'string') { |
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.
Nitpick: typeof parsedYaml.profileName !== 'string'
would suffice here since undefined
is not a string.´?
src/utils/ProfileUtils.ts
Outdated
'Ensure that the profile import file isn\'t corrupted.' | ||
) | ||
} | ||
if (!parsedYaml.mods || typeof parsedYaml.mods !== 'object') { |
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.
Looking at old L130/new L151 it looks like we're expecting an array, and while object might be an array, it might not. Using if(!Array.isArray(parsedYaml.mods) {
would be more accurate, shorter, and make the intent clearer to the reader.
4b6392e
to
61d1ce4
Compare
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.
Nice 👍🏻
No description provided.