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
2 changes: 1 addition & 1 deletion .github/workflows/tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
with:
release-branches: '["main"]'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.PAT }}
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ linters:
- durationcheck # checks for two durations multiplied together
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
- execinquery # checks query string in Query function which reads your Go src files and warning it finds
- exhaustive # checks exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables
- forbidigo # forbids identifiers
Expand Down Expand Up @@ -267,6 +266,7 @@ linters:
#- depguard # [replaced by gomodguard] checks if package imports are in a list of acceptable packages
#- dogsled # checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
#- dupword # [useless without config] checks for duplicate words in the source code
#- execinquery # checks query string in Query function which reads your Go src files and warning it finds
#- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/errchkjson] checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted
#- forcetypeassert # [replaced by errcheck] finds forced type assertions
#- goerr113 # [too strict] checks the errors handling expressions
Expand Down
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Oops, Errors

[![Go Reference](https://pkg.go.dev/badge/github.com/jesse0michael/oops.svg)](https://pkg.go.dev/github.com/jesse0michael/oops)

Error handling for adding attributes and source location to errors when logging them.

Inspired by [https://github.com/samber/oops](https://github.com/samber/oops) with a minimal API.

Works with [log/slog](https://pkg.go.dev/log/slog) through a [LogerValue]() that decorates the logged error attribute with the attributes and source location to any `oops.Error`.
Works with [log/slog](https://pkg.go.dev/log/slog) through a [LogValue](https://pkg.go.dev/log/slog#LogValuer) that decorates the logged error attribute with the attributes and source location to any `oops.Error`.

## Example

Expand Down Expand Up @@ -38,21 +40,23 @@ func main() {
}
```

>{
> "time":"2025-02-01T21:59:54.959869-07:00",
> "level":"ERROR",
> "msg":"error",
> "err":{
> "err":"process not found",
> "id":"oops",
> "method":"Run",
> "source":{
> "file":"#####/github.com/jesse0michael/oops/README.md",
> "function":"github.com/jesse0michael/oops.process",
> "line":30
> }
> }
>}
```json
{
"time":"2025-02-01T21:59:54.959869-07:00",
"level":"ERROR",
"msg":"error",
"err":{
"err":"process not found",
"id":"oops",
"method":"Run",
"source":{
"file":"#####/github.com/jesse0michael/oops/README.md",
"function":"github.com/jesse0michael/oops.process",
"line":30
}
}
}
```

This example highlights some of the different ways to create and decorate errors by dropping in the oops package. Create a new error with `oops.New` or wrap an existing error with `oops.Wrap` or use `oops.Errorf` to format an error message.

Expand Down