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

CheckWriteHook: Don't allow Noop action #1089

Merged
merged 2 commits into from Apr 29, 2022
Merged

CheckWriteHook: Don't allow Noop action #1089

merged 2 commits into from Apr 29, 2022

Conversation

abhinav
Copy link
Collaborator

@abhinav abhinav commented Apr 29, 2022

In #1088, we deprecated the CheckWriteAction enum in favor of the new
fully customizable CheckWriteHook. Unfortunately, this introduced a
minor regression: it's now possible to set log.Fatal to no-op with
WriteThenNoop.

Such a configuration will break code that looks like the following:

f, err := os.Open(..)
if err != nil {
    log.Fatal("Cannot open file", zap.Error(err))
}

// Control flow expects that if we get here,
// f is valid and non-nil.
// That's not the case if Fatal no-ops.

fmt.Println(f.Name())

This change fixes the regression by turning Noops into WriteThenFatal
when logging Fatal log messages. This matches the old behavior.

It further clarifies the documentation for CheckWriteHook so that users
know to call runtime.Goexit or os.Exit in them. It's still possible to
write a custom hook that no-ops the log.Fatal, but it requires a little
extra effort from the user to do so.

In #1088, we deprecated the CheckWriteAction enum in favor of the new
fully customizable CheckWriteHook. Unfortunately, this introduced a
minor regression: it's now possible to set log.Fatal to no-op with
WriteThenNoop.

Such a configuration will break code that looks like the following:

```go
f, err := os.Open(..)
if err != nil {
    log.Fatal("Cannot open file", zap.Error(err))
}

// Control flow expects that if we get here,
// f is valid and non-nil.
// That's not the case if Fatal no-ops.

fmt.Println(f.Name())
```

This change fixes the regression by turning Noops into WriteThenFatal
when logging Fatal log messages. This matches the old behavior.

It further clarifies the documentation for CheckWriteHook so that users
know to call runtime.Goexit or os.Exit in them. It's still possible to
write a custom hook that no-ops the log.Fatal, but it requires a little
extra effort from the user to do so.
@codecov
Copy link

codecov bot commented Apr 29, 2022

Codecov Report

Merging #1089 (ba9689d) into master (71ecc42) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1089   +/-   ##
=======================================
  Coverage   98.36%   98.36%           
=======================================
  Files          49       49           
  Lines        2142     2142           
=======================================
  Hits         2107     2107           
  Misses         27       27           
  Partials        8        8           
Impacted Files Coverage Δ
options.go 100.00% <ø> (ø)
zapcore/entry.go 93.97% <ø> (ø)
logger.go 96.52% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 71ecc42...ba9689d. Read the comment docs.

@abhinav abhinav requested a review from sywhang April 29, 2022 17:08
@abhinav abhinav merged commit 9e61a39 into master Apr 29, 2022
@abhinav abhinav deleted the checkwrite-noop branch April 29, 2022 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants