WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit bd16496

Browse files
authored
Merge pull request #26 from lainio/refactor
refactor
2 parents ece6e9a + faeb192 commit bd16496

File tree

16 files changed

+160
-150
lines changed

16 files changed

+160
-150
lines changed

.golangci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ linters:
6262
# - errorlint
6363
# - exhaustive
6464
# - exhaustivestruct
65-
- exportloopref
65+
# - exportloopref -> copyloopvar # but we are using go 1.18
6666
# - forbidigo
6767
# - forcetypeassert
6868
- funlen
@@ -92,6 +92,7 @@ linters:
9292
- ineffassign
9393
# - ireturn
9494
# - lll
95+
# - copyloopvar # we have go 1.18
9596
- makezero
9697
- misspell
9798
- nakedret

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
### Version history
44

5+
##### 1.2.0
6+
- Now `-err2-ret-trace` and `err2.SetErrRetTracer` gives us *error return traces*
7+
which are even more readable than `-err2-trace`, `err2.SetErrorTracer` with
8+
long error return traces
9+
- A new automatic error formatter/generator added for `TryCopyFile` convention
10+
- New features for `sample/` to demonstrate latest features
11+
- Extended documentation
12+
513
##### 1.1.0
614
- `assert` package:
715
- bug fix: call stack traversal during unit testing in some situations

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,6 @@ Please see the full version history from [CHANGELOG](./CHANGELOG.md).
623623
624624
### Latest Release
625625
626-
##### 1.2.0
627-
- Now `-err2-ret-trace` and `err2.SetErrRetTracer` gives us *error return traces*
628-
which are even more readable than `-err2-trace`, `err2.SetErrorTracer` with
629-
long error return traces
630-
- A new automatic error formatter/generator added for `TryCopyFile` convention
631-
- New features for `sample/` to demonstrate latest features
632-
- Extended documentation
626+
##### 1.2.1
627+
- Optimization and Refactoring
628+
- Updated documentation

assert/assert.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,27 +1062,23 @@ func PushAsserter(i Asserter) (retFn function) {
10621062
var (
10631063
prevFound bool
10641064
prevAsserter asserter
1065+
currentGID int
10651066
)
10661067

10671068
// get pkg lvl asserter
10681069
curAsserter := defAsserter[def]
10691070
// .. to check if we are doing unit tests
10701071
if !curAsserter.isUnitTesting() {
10711072
// .. allow GLS specific asserter. NOTE see current()
1072-
curGoRID := goid()
1073-
//asserterMap.Set(curGoRID, defAsserter[i])
1073+
currentGID = goid()
10741074
asserterMap.Tx(func(m map[int]asserter) {
1075-
cur, found := m[curGoRID]
1076-
if found {
1077-
prevAsserter = cur
1078-
prevFound = found
1079-
}
1080-
m[curGoRID] = defAsserter[i]
1075+
prevAsserter, prevFound = m[currentGID]
1076+
m[currentGID] = defAsserter[i]
10811077
})
10821078
}
10831079
if prevFound {
10841080
return func() {
1085-
asserterMap.Set(goid(), prevAsserter)
1081+
asserterMap.Set(currentGID, prevAsserter)
10861082
}
10871083
}
10881084
return PopAsserter

doc.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ err2 offers optional stack tracing. And yes, it's fully automatic. Just call
7171
at the beginning your app, e.g. main function, or set the tracers
7272
programmatically (before [flag.Parse] if you are using that):
7373
74-
err2.SetErrorTracer(os.Stderr) // write error stack trace to stderr
74+
err2.SetErrRetTracer(os.Stderr) // write error return trace to stderr
75+
or
76+
err2.SetErrorTracer(os.Stderr) // write error stack trace to stderr
7577
or
7678
err2.SetPanicTracer(log.Writer()) // panic stack trace to std logger
7779
@@ -80,7 +82,8 @@ practice still print their stack trace. The panic tracer's default values is
8082
[os.Stderr]. The default error tracer is nil.
8183
8284
err2.SetPanicTracer(os.Stderr) // panic stack tracer's default is stderr
83-
err2.SetErrorTracer(nil) // error stack tracer's default is nil
85+
err2.SetErrRetTracer(nil) // error return tracer's default is nil
86+
err2.SetErrorTracer(nil) // error stack tracer's default is nil
8487
8588
Note that both panic and error traces are optimized by err2 package. That means
8689
that the head of the stack trace isn't the panic function, but an actual line
@@ -105,12 +108,14 @@ tracer API:
105108
The err2 package supports Go's flags. All you need to do is to call [flag.Parse].
106109
And the following flags are supported (="default-value"):
107110
108-
-err2-log="nil"
109-
A name of the stream currently supported stderr, stdout or nil
110-
-err2-panic-trace="stderr"
111-
A name of the stream currently supported stderr, stdout or nil
112-
-err2-trace="nil"
113-
A name of the stream currently supported stderr, stdout or nil
111+
-err2-log stream
112+
stream for logging: nil -> log pkg
113+
-err2-panic-trace stream
114+
stream for panic tracing (default stderr)
115+
-err2-ret-trace stream
116+
stream for error return tracing: stderr, stdout
117+
-err2-trace stream
118+
stream for error tracing: stderr, stdout
114119
115120
Note that you have called [SetErrorTracer] and others, before you call
116121
[flag.Parse]. This allows you set the defaults according your app's need and allow

0 commit comments

Comments
 (0)