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

Add error handling for when the profile file yaml parsing fails #1523

Merged
merged 3 commits into from
Nov 6, 2024

Conversation

VilppeRiskidev
Copy link
Collaborator

No description provided.

@VilppeRiskidev VilppeRiskidev self-assigned this Nov 5, 2024
Copy link
Collaborator

@anttimaki anttimaki left a 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) {
Copy link
Collaborator

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.

'Ensure that the profile import file isn\'t corrupted.'
)
}
if (!parsedYaml.profileName || typeof parsedYaml.profileName !== 'string') {
Copy link
Collaborator

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.´?

'Ensure that the profile import file isn\'t corrupted.'
)
}
if (!parsedYaml.mods || typeof parsedYaml.mods !== 'object') {
Copy link
Collaborator

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.

Copy link
Collaborator

@anttimaki anttimaki left a comment

Choose a reason for hiding this comment

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

Nice 👍🏻

@anttimaki anttimaki merged commit 71158d9 into develop Nov 6, 2024
5 checks passed
@anttimaki anttimaki deleted the handle-corrupted-profile-import-errors branch November 6, 2024 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants