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

parser: swap all log.Errorf calls with error values #75

Merged
merged 1 commit into from
Jan 9, 2023

Conversation

mvdan
Copy link
Contributor

@mvdan mvdan commented Nov 14, 2022

(see commit message)

Updates #70.

@mvdan
Copy link
Contributor Author

mvdan commented Nov 14, 2022

cc @stapelberg

@mvdan
Copy link
Contributor Author

mvdan commented Nov 14, 2022

I somehow broke the tests, sorry. Be right back.

As I was working on my patch for protocolbuffers#70, I was wondering if we really
needed a logger interface with both Infof and Errorf. After all, a
library should report its errors as values, not via a logger.

Turns out it's relatively straightforward to do so. All functions that
used to call log.Errorf are themselves called from top-level APIs which
are able to return an error, so we just need to thread them.

One special case is getMetaCommentStringValues, which used to report
each error and continue rather than stop. We currently do not have an
idiomatic way to report multiple errors at once, so return the first
error for now. In the future, we could use https://go.dev/issue/53435.

Updates protocolbuffers#70.
@mvdan mvdan force-pushed the parser-log-errorf branch from 218d9bf to 4454a9b Compare November 14, 2022 08:57
@mvdan
Copy link
Contributor Author

mvdan commented Nov 14, 2022

Should be ready now.

@stapelberg
Copy link

The current approach results in a bunch of behavioral changes — what previously was skipped (with an error logged) now aborts the entire formatting, right?

I’m not sure if this is safe to do (cc @kssilveira).

Maybe a more straight-forward change would be to introduce an interface to specify the logger, which we can then hook up to glog internally, but which defaults to the standard library’s log package externally?

@mvdan
Copy link
Contributor Author

mvdan commented Nov 14, 2022

To be clear, that's the path I was taking initially, but it felt wrong to document an API which both returns errors and logs errors. That's why I thought - perhaps we can treat all errors equally by returning.

Fine with me if that's not an acceptable change of behavior, I can close this PR and go back to the original plan. Perhaps a better way to deal with the confusion, then, would be that the logger only deals with Infof and Warnf - then all errors are consistently returned and never logged.

@stapelberg
Copy link

(To be clear, I’m not saying this is unacceptable, just saying it needs a careful look by @kssilveira and potentially a global test run.)


Maybe the logger can even have just a single method, and it’s up to the caller to decide whether to hook up these messages to info/warning/error leveled logs.

@mvdan
Copy link
Contributor Author

mvdan commented Nov 14, 2022

Maybe the logger can even have just a single method, and it’s up to the caller to decide whether to hook up these messages to info/warning/error leveled logs.

I don't think that's a good idea, given that some of the logs are very noisy and for debugging, and some others are showing ignored errors/warnings.

@Nexucis
Copy link

Nexucis commented Nov 23, 2022

any update on this ? would be cool to have this :) and hopefully seeing this patch in cue v0.5

@mvdan
Copy link
Contributor Author

mvdan commented Nov 23, 2022

@Nexucis cue v0.5 is almost done, so we wouldn't bump a dependency unless we absolutely have to at this point.

This PR does change behavior, and it sounds like the actual maintainers aren't very active, so I'll send a non-breaking PR with my original plan instead. I'm still not a big fan of a library reporting errors in two ways, but it's already doing that in any case :)

@kssilveira
Copy link
Member

kssilveira commented Nov 23, 2022 via email

@kssilveira
Copy link
Member

I will try this inside Google to see if something breaks and report back.

@kssilveira
Copy link
Member

Trying now to see what breaks.

@mvdan
Copy link
Contributor Author

mvdan commented Jan 7, 2023

Since the focus is on #77 now, I assume we should drop this one?

In an ideal world I'd prefer the library to return errors as some form of multi-errors, rather than log them, but the priority is definitely to just remove glog :)

@kssilveira
Copy link
Member

I didn't find any test failure caused by this change, so we can do both.

@mvdan
Copy link
Contributor Author

mvdan commented Jan 9, 2023

Ah neat. In that case, if you merge this first, then the logger changes will become a lot easier - I would refactor the other PR a bit.

@kssilveira kssilveira merged commit db1d62a into protocolbuffers:master Jan 9, 2023
@mvdan
Copy link
Contributor Author

mvdan commented Jan 9, 2023

@kssilveira it seems like the merge got reverted by 5ecdd59, is that by design? I can't really refactor the other PR to sit on top of this one if master doesn't include the changes :)

@kssilveira
Copy link
Member

Sorry! I am still learning to deal with external contributions, I think I was not supposed to click the merge button here, instead I need to merge it internally first and then the robot will mark it as merged.

Could you make a pull request again? I will try to properly accept it this time.

@mvdan
Copy link
Contributor Author

mvdan commented Jan 12, 2023

Ah, no worries. Master is causing conflicts in the meantime, unfortunately, so I'll try to solve those.

@mvdan
Copy link
Contributor Author

mvdan commented Jan 12, 2023

Done in #84.

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

Successfully merging this pull request may close these issues.

4 participants