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

Panic vs Error #77

Open
alimoeeny opened this issue Oct 28, 2022 · 2 comments
Open

Panic vs Error #77

alimoeeny opened this issue Oct 28, 2022 · 2 comments

Comments

@alimoeeny
Copy link
Contributor

Hi @galeone :)
And as always, thank you for the hard work and for keeping the lights on.

I was wondering if you think it is possible to reduce the number of panic calls in this repository?
Would it be okay if I send you PRs that would remove the calls to panic and instead return an error?
If you think that is a reasonable thing to do, I assume we might need a separate develop branch for a while since these will be breaking changes (I mean backward incompatible) due to the changes in the signature of these functions?

One example is

panic(fmt.Errorf("unsupported image extension %s", ext))

where image.Read can return an error if the file extension is not recognized, rather than calling panic

@galeone
Copy link
Owner

galeone commented Oct 28, 2022 via email

@alimoeeny
Copy link
Contributor Author

Thanks @galeone , I see. let me think about it, I am sure there are ways to pass the error along while keeping the chaining.
I don't think any of them are very "idiomatic" though.
Let's think about it and see if we can find a solution that is elegant and practical.

  • My immediate reaction was, we can have separate functions / wrappers one set for channing and one set for more idiomatic use, like image.Read is for chaining and image.ReadWithError or image.ReadNP (for No Panic) or image.IRead for idiomatic read :D but this is not an elegant solution.
  • then I thought how about passing in a error channel or a pointer to an error so that each function can check if the previous link in the chain has reported any errors. but that is not elegant either

I'll think about it and let you know if I find any good solutions.

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