Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@

## API and Compatibility Notes
- Do not introduce new usage of deprecated `Cause()`; prefer `errors.Is`/`errors.As` compatible flows and `Unwrap`/`Unwraps`.
- Keep `errs.Join` behavior stable: ignore nil arguments and return nil when all arguments are nil.
- Treat changes to exported symbols, function signatures, and observable error formatting behavior as potentially breaking.
- Error string and JSON formatting are validated by tests; when output behavior changes, update README examples and test expectations in the same change.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ For multiple causes, it returns all causes as a slice.
- `errs.New("")` returns `nil`
- `errs.Wrap(nil)` returns `nil`
- If `WithCause` is given multiple times, the last cause is used
- `errs.Join(...)` ignores `nil` arguments and returns `nil` if all arguments are `nil`

### Create new error instance with cause

Expand Down
2 changes: 2 additions & 0 deletions errlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type Errors struct {
}

// Join function returns Errors instance.
//
// Join ignores nil elements in arguments and returns nil if all elements are nil.
func Join(errlist ...error) error {
if len(errlist) == 0 {
return nil
Expand Down
14 changes: 11 additions & 3 deletions zapobject/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"go.uber.org/zap"
)

func checkFileOpen(path string) error {
func checkFileOpen(path string) (retErr error) {
file, err := os.Open(path)
if err != nil {
return errs.New(
Expand All @@ -19,7 +19,15 @@ func checkFileOpen(path string) error {
errs.WithContext("path", path),
)
}
defer file.Close()
defer func() {
if err := file.Close(); err != nil {
closeErr := errs.Wrap(
err,
errs.WithContext("path", path),
)
retErr = errs.Join(retErr, closeErr)
}
}()

return nil
}
Expand All @@ -41,7 +49,7 @@ func generateMultiError() error {

func Example() {
logger := zap.NewExample()
defer logger.Sync()
defer func() { _ = logger.Sync() }()

if err := checkFileOpen("not-exist.txt"); err != nil {
logger.Error("err", zap.Object("error", zapobject.New(err)))
Expand Down
Loading