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

warning: support new option to override default #216

Merged
merged 3 commits into from
Feb 2, 2021

Conversation

ffromani
Copy link
Collaborator

@ffromani ffromani commented Jan 25, 2021

This PR wants to solve #175

This patch add support for a new option, which allow
the caller code to pass a new Alerter to ghw.
Alerter is a dead-simple interface, supporting only a
Printf method much like the stdlib log package.
ghw will send all the warnings to this method.

We use a so simple interface because we want to generalize a bit
the existing util.Warn concept, but is not clear if ghw will benefit
of a more complete logging interface; should that be the case, we
can build on the concept we laid in this patch.

Client code can programmatically override the Alerter, or
users can using the faimiliar GHW_DISABLE_WARNINGS environ variable,
which keep functioning as usual.

ghw can be configured to swallow all the warnings or to keep emitting them
on stderr, like it used to do up until this patch.

Signed-off-by: Francesco Romani [email protected]

@ffromani
Copy link
Collaborator Author

WIP because while the code is {mostly, hopefully} straightforward, there are quite some design concepts to properly evaluate here.
For example: do default (trivial) Alerters belong in the option pkg?

Also, tests are completely missing and we need at least basic coverage.

@@ -18,12 +18,15 @@ type Context struct {
SnapshotPath string
SnapshotRoot string
SnapshotExclusive bool
SnapshotPreserve bool
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

bad rebase, will fix in the next upload which I need to do anyway to add tests.

Copy link
Owner

Choose a reason for hiding this comment

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

@fromanirh you still working on this patch, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes! totally ongoing, but not sure I can make it for end of the week (aka 0.7 cutoff).

Copy link
Owner

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

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

👍 I like this.

@ffromani ffromani changed the title WIP warning: support new option to override default warning: support new option to override default Jan 28, 2021
@ffromani
Copy link
Collaborator Author

Ok, managed to do some of the updates I planned and I'm reasonnably happy with the state of the PR. We can iterate and improve a bit later; WIP removed, PR fully reviewable!

This patch add support for a new option, which allow
the caller code to pass a new Alerter to ghw.
`Alerter` is a dead-simple interface, supporting only a
`Printf` method much like the stdlib `log` package.
ghw will send all the warnings to this method.

We use a so simple interface because we want to generalize a bit
the existing `util.Warn` concept, but is not clear if ghw will benefit
of a more complete logging interface; should that be the case, we
can build on the concept we laid in this patch.

Client code can programmatically override the Alerter, or
users can using the faimiliar `GHW_DISABLE_WARNINGS` environ variable,
which keep functioning as usual.

ghw can be configured to swallow all the warnings or to keep emitting
them on stderr, like it used to do up until this patch.

Signed-off-by: Francesco Romani <[email protected]>
@ffromani
Copy link
Collaborator Author

fixed stale commit message. No code changes.

Copy link
Owner

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

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

suggestion inline :)

Make it easier for users of the ghw API to disable warnings
providing a `NullAlerter`.

Signed-off-by: Francesco Romani <[email protected]>
Copy link
Owner

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

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

eccellente! grazie @fromanirh! :)


You may also supply an `Alerter` to ghw to handle the warnings.
In this case, please check the `option.Alerter` interface (compatible with stdlib's
log.Logger type) and the `ghw.WithAlerter()` function
```
Copy link
Owner

Choose a reason for hiding this comment

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

👍

@ffromani
Copy link
Collaborator Author

ffromani commented Jan 28, 2021

just wild thought reviewing #175: do we want to add an alias, perhaps in another PR, to minimize the surprise for users? Programmatically we have WithNullAlerter, using env vars we have GHW_DISABLE_WARNINGS.
We can add

var WithDisableWarnings = option.WithNullAlerter

I believe we should keep WithNullAlerter because it's more powerful construct.

@jaypipes
Copy link
Owner

just wild thought reviewing #175: do we want to add an alias, perhaps in another PR, to minimize the surprise for users? Programmatically we have WithNullAlerter, using env vars we have GHW_DISABLE_WARNINGS.
We can add

var WithDisableWarnings = option.WithNullAlerter

I believe we should keep WithNullAlerter because it's more powerful construct.

Sure! Go for it :)

With this patch we make the ghw API more consistent,
matching the more generic Alerter subsystem with the existing
`GHW_DISABLE_WARNINGS` environ variables, with minimal
cost and with the added benefit to minimize users' surprise.

Signed-off-by: Francesco Romani <[email protected]>
@ffromani
Copy link
Collaborator Author

Done! Now I think we have everything we need to call #175 really done.

Copy link
Owner

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

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

Excellent, thank you @fromanirh!

@jaypipes jaypipes merged commit 38a8f62 into jaypipes:master Feb 2, 2021
@ffromani ffromani deleted the warning-machinery branch May 24, 2021 06:52
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.

2 participants