Skip to content

Tolerate empty annotation file, throw better error#612

Merged
subdavis merged 6 commits into
mainfrom
desktop/json-load-fix
Mar 8, 2021
Merged

Tolerate empty annotation file, throw better error#612
subdavis merged 6 commits into
mainfrom
desktop/json-load-fix

Conversation

@subdavis
Copy link
Copy Markdown
Contributor

@subdavis subdavis commented Mar 2, 2021

don't think we'll hear back on this issue. Either way, this is a problem.

@subdavis subdavis added the skipped-planning Issue that skipped our team planning process. label Mar 3, 2021
@subdavis subdavis marked this pull request as ready for review March 3, 2021 18:19
@subdavis subdavis requested a review from BryonLewis March 3, 2021 18:19
Copy link
Copy Markdown
Collaborator

@BryonLewis BryonLewis left a comment

Choose a reason for hiding this comment

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

More a comment about how the determine no file vs bad file

Comment on lines +135 to +140
if (rawBuffer.length < 5) {
/**
* 5 is somewhat arbitrary, and accounts for newline chars
* This cannot possibly be a valid file. Return empty
*/
return {};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not exactly sure how I feel about this. A file that is truly empty or a file that is just {} feels different than a file that contains 12345 or null (it shouldn't have it but who knows) or something else that falls within that 5 limit but cannot be parsed. Feels like it should error then. Should we have explicit cases where it works: Missing file, blank file or empty object file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm guarding against newline characters that make the file look empty.

I think you're right that this is too permissive. Perhaps we should strip newlines from the input before parsing, then safely handle the 0 length case, and otherwise throw an error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Overthinking it. Need to handle the empty file case, but otherwise, I think a parser error is appropriate.

@subdavis subdavis requested a review from BryonLewis March 8, 2021 16:05
Copy link
Copy Markdown
Collaborator

@BryonLewis BryonLewis left a comment

Choose a reason for hiding this comment

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

As long as we throw the error telling them why, this looks good.

@subdavis subdavis merged commit e8d4697 into main Mar 8, 2021
@subdavis subdavis deleted the desktop/json-load-fix branch March 8, 2021 18:30
@subdavis subdavis added skipped-planning Issue that skipped our team planning process. and removed skipped-planning Issue that skipped our team planning process. labels Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skipped-planning Issue that skipped our team planning process.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants