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

Prevent size related exceptions #307

Merged
merged 5 commits into from Jan 19, 2020
Merged

Conversation

Borewit
Copy link
Collaborator

@Borewit Borewit commented Jan 17, 2020

Prevent exceptions:

@Borewit Borewit added the bug label Jan 17, 2020
@Borewit Borewit self-assigned this Jan 17, 2020
@Borewit
Copy link
Collaborator Author

Borewit commented Jan 18, 2020

I am not really happy with way the maybeless flag is now provided to tokenizer.peekBuffer in:

await tokenizer.peekBuffer(buffer, 0, bytesRead, tokenizer.position, true); //maybeless = true

I have created an issue: strtok3#124

core.js Show resolved Hide resolved
await FileType.fromBuffer(buf);
}, `file size = ${size} bytes`);
const buffer = Buffer.alloc(size);
await t.notThrowsAsync(FileType.fromBuffer(buffer), `File size: ${size} bytes`);
Copy link
Owner

Choose a reason for hiding this comment

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

I have no idea why this is failing:

✖ odd file sizes t.notThrowsAsync() must be called with a function or promise

FileType.fromBuffer(buffer) is a Promise.

Copy link
Collaborator Author

@Borewit Borewit Jan 19, 2020

Choose a reason for hiding this comment

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

I am happy I am not the only one anymore who thinks the behavior of the async tests methods are weird. Passing a promise should be sufficient.

test.js is full of redundant await statements.

I think in general async tests methods & await statements could be avoided by treating the test method async if the return type of the test method is a promise.

Copy link
Owner

Choose a reason for hiding this comment

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

Ok, I know why it happens. When the file type cannot be detected, .fromBuffer() incorrectly returns undefined instead of Promise<undefined>.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Aij

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is missing async declaration:

function fromBuffer(input) {

Copy link
Collaborator Author

@Borewit Borewit Jan 19, 2020

Choose a reason for hiding this comment

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

I will create separate issue / PR for that. I am curious if the test cases are then working with a single await as well.

... issue created: #309

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And indeed, with the async fix, the async-test- methods do behave as expected 😁

@Borewit Borewit force-pushed the prevent-size-related-exceptions branch from 2a431bd to 7ce5d76 Compare January 19, 2020 10:49
@Borewit
Copy link
Collaborator Author

Borewit commented Jan 19, 2020

Force pushed a rebase on PR #310.

@sindresorhus sindresorhus merged commit 936b020 into master Jan 19, 2020
@sindresorhus sindresorhus deleted the prevent-size-related-exceptions branch January 19, 2020 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

inconsistent behavior for small size buffer
2 participants