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

Throw Errors from Load Function #5

Open
obermillerk opened this issue May 29, 2020 · 4 comments
Open

Throw Errors from Load Function #5

obermillerk opened this issue May 29, 2020 · 4 comments

Comments

@obermillerk
Copy link

obermillerk commented May 29, 2020

Looking to use this library as I'll be loading in npy files. I was looking at the source code and noticed that you're catching potential errors in the load function and just printing them to console.error. I would like to suggest that those errors are allowed to propagate out of the function, so the developer can handle them instead of having them go to the console.

The callback might be an issue. My ideas on that would be to either add a second errorCallback, or a second error argument to the first callback. I'd be happy to put together a PR as well if that helps!

Edit: I should clarify, the second argument method I think should follow the error-first callback schema, so the result would then be in the second argument. This would be a change in the way the module works, and would possibly warrant a minor version bump if accepted. The errorCallback method would not change existing functionality as it could simply be omitted, which may be preferable.

@j6k4m8
Copy link
Member

j6k4m8 commented May 30, 2020

This is an excellent point — a PR of your suggestion would be hugely appreciated!

Could you explain your preference for the error to be the first callback? Might make sense to keep backward-compatible ordering for now, but I can be convinced :D

@obermillerk
Copy link
Author

obermillerk commented May 30, 2020

My apologies, I guess my edit was unclear. I meant that in the case of adding a second argument to the callback, we should follow the error-first callback convention from before promises where there is a single callback that is passed two arguments. The first argument is any error that happened, or null if none happened in which case there's a second argument that is the normal result as is passed to the callback now. This would not be backward compatible.

If a second callback specifically for errors were added, I agree that would be better as a second callback as this would be backward compatible. I can go with this one since it sounds like your preference is not to break backwards compatibility. I can work on a PR tomorrow probably.

@j6k4m8
Copy link
Member

j6k4m8 commented May 30, 2020

Aha! Now I understand. Got it, thank you for explaining!

My preference is (success, error) for now with the plan to change it in the next version roll.
it would be nice to preserve backward compatibility if that is acceptable for your use case. But hey, you're the one writing the PR ;)

@obermillerk
Copy link
Author

I can certainly do that, I'll be using promises anyway.

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

No branches or pull requests

2 participants