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
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ linters:
# - errorlint
# - exhaustive
# - exhaustivestruct
- exportloopref
# - exportloopref -> copyloopvar # but we are using go 1.18
# - forbidigo
# - forcetypeassert
- funlen
Expand Down Expand Up @@ -92,6 +92,7 @@ linters:
- ineffassign
# - ireturn
# - lll
# - copyloopvar # we have go 1.18
- makezero
- misspell
- nakedret
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

### Version history

##### 1.2.0
- Now `-err2-ret-trace` and `err2.SetErrRetTracer` gives us *error return traces*
which are even more readable than `-err2-trace`, `err2.SetErrorTracer` with
long error return traces
- A new automatic error formatter/generator added for `TryCopyFile` convention
- New features for `sample/` to demonstrate latest features
- Extended documentation

##### 1.1.0
- `assert` package:
- bug fix: call stack traversal during unit testing in some situations
Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,6 @@ Please see the full version history from [CHANGELOG](./CHANGELOG.md).

### Latest Release

##### 1.2.0
- Now `-err2-ret-trace` and `err2.SetErrRetTracer` gives us *error return traces*
which are even more readable than `-err2-trace`, `err2.SetErrorTracer` with
long error return traces
- A new automatic error formatter/generator added for `TryCopyFile` convention
- New features for `sample/` to demonstrate latest features
- Extended documentation
##### 1.2.1
- Optimization and Refactoring
- Updated documentation
14 changes: 5 additions & 9 deletions assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -1062,27 +1062,23 @@ func PushAsserter(i Asserter) (retFn function) {
var (
prevFound bool
prevAsserter asserter
currentGID int
)

// get pkg lvl asserter
curAsserter := defAsserter[def]
// .. to check if we are doing unit tests
if !curAsserter.isUnitTesting() {
// .. allow GLS specific asserter. NOTE see current()
curGoRID := goid()
//asserterMap.Set(curGoRID, defAsserter[i])
currentGID = goid()
asserterMap.Tx(func(m map[int]asserter) {
cur, found := m[curGoRID]
if found {
prevAsserter = cur
prevFound = found
}
m[curGoRID] = defAsserter[i]
prevAsserter, prevFound = m[currentGID]
m[currentGID] = defAsserter[i]
})
}
if prevFound {
return func() {
asserterMap.Set(goid(), prevAsserter)
asserterMap.Set(currentGID, prevAsserter)
}
}
return PopAsserter
Expand Down
21 changes: 13 additions & 8 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ err2 offers optional stack tracing. And yes, it's fully automatic. Just call
at the beginning your app, e.g. main function, or set the tracers
programmatically (before [flag.Parse] if you are using that):

err2.SetErrorTracer(os.Stderr) // write error stack trace to stderr
err2.SetErrRetTracer(os.Stderr) // write error return trace to stderr
or
err2.SetErrorTracer(os.Stderr) // write error stack trace to stderr
or
err2.SetPanicTracer(log.Writer()) // panic stack trace to std logger

Expand All @@ -80,7 +82,8 @@ practice still print their stack trace. The panic tracer's default values is
[os.Stderr]. The default error tracer is nil.

err2.SetPanicTracer(os.Stderr) // panic stack tracer's default is stderr
err2.SetErrorTracer(nil) // error stack tracer's default is nil
err2.SetErrRetTracer(nil) // error return tracer's default is nil
err2.SetErrorTracer(nil) // error stack tracer's default is nil

Note that both panic and error traces are optimized by err2 package. That means
that the head of the stack trace isn't the panic function, but an actual line
Expand All @@ -105,12 +108,14 @@ tracer API:
The err2 package supports Go's flags. All you need to do is to call [flag.Parse].
And the following flags are supported (="default-value"):

-err2-log="nil"
A name of the stream currently supported stderr, stdout or nil
-err2-panic-trace="stderr"
A name of the stream currently supported stderr, stdout or nil
-err2-trace="nil"
A name of the stream currently supported stderr, stdout or nil
-err2-log stream
stream for logging: nil -> log pkg
-err2-panic-trace stream
stream for panic tracing (default stderr)
-err2-ret-trace stream
stream for error return tracing: stderr, stdout
-err2-trace stream
stream for error tracing: stderr, stdout

Note that you have called [SetErrorTracer] and others, before you call
[flag.Parse]. This allows you set the defaults according your app's need and allow
Expand Down
Loading
Loading