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

Remove hard-coded logging #11

Open
ivanjaros opened this issue Jan 11, 2023 · 4 comments
Open

Remove hard-coded logging #11

ivanjaros opened this issue Jan 11, 2023 · 4 comments

Comments

@ivanjaros
Copy link

If there is error during rendering, like missing image, I will get a log:

2023/01/11 16:45:04 IMAGE ERROR: foobar, file does not exist

This is not good because I have no control over this. I don't even think this should be a log. It should be simply returned error which can be ignored, or not. Adding something like WithLog(someInterace) may sound like good idea at first but in reality it is useless. Hence I think there should dedicated error that can join multiple errors(multiple missing images) which can be then processed by the caller or ignored, depending on severity(ie var ErrMissingImage = errors.New(...) with errors.Is()). The final document can still be used even with missing images hence why it should not be a hard error. Also, this specifically ties to #7

@stephenafamo
Copy link
Owner

stephenafamo commented Jan 11, 2023

I'll just wait untill Go 1.20 releases in the next few months which allow wrapping of multiple errors.

The downside is that it will then require any users to upgrade to 1.20, but everything should be backwards compatible so no issues there.

Then it'll be easy to ignore missing image errors with something like

if err != nil && !errors.Is(err, pdf.ErrMissingImage) {
    // ....
}

EDIT: That may not work, because that will suppress every error if any error is the pdf.ErrMissingImage

@ivanjaros
Copy link
Author

That's what unwrapping of errors is for. That is of no concern. I think that missing images should not even cause errors to begin with. As the alt issue i linked, the document should render alt text or some placeholder.

@stephenafamo
Copy link
Owner

I agree it shouldn't prevent rendering and should use the alt text instead.

Still, a user should have a way to know if such a thing happens during rendering, for example, a browser will show a console error and an error in the network tab.

Maybe a middle ground will be an option to indicate whether not-found images should be treated as errors or not

@ivanjaros
Copy link
Author

True, but you are rendering essentially an html page where missing images are perfectly fine and the sole reason alt even exists. If this would be a dedicated pdf builder/renderer, sure, but it is not. It's literally markdown renderer.

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