@@ -44,10 +44,11 @@ func CopyFile(src, dst string) (err error) {
44
44
- [ Filters for non-errors like io.EOF] ( #filters-for-non-errors-like-ioeof )
45
45
- [ Backwards Compatibility Promise for the API] ( #backwards-compatibility-promise-for-the-api )
46
46
- [ Assertion] ( #assertion )
47
+ - [ Asserters] ( #asserters )
47
48
- [ Assertion Package for Runtime Use] ( #assertion-package-for-runtime-use )
48
49
- [ Assertion Package for Unit Testing] ( #assertion-package-for-unit-testing )
49
50
- [ Automatic Flags] ( #automatic-flags )
50
- - [ Support for Cobra Flags] ( support-for-cobra-flags )
51
+ - [ Support for Cobra Flags] ( # support-for-cobra-flags)
51
52
- [ Code Snippets] ( #code-snippets )
52
53
- [ Background] ( #background )
53
54
- [ Learnings by so far] ( #learnings-by-so-far )
@@ -162,6 +163,10 @@ If no `Tracer` is set no stack tracing is done. This is the default because in
162
163
the most cases proper error messages are enough and panics are handled
163
164
immediately by a programmer.
164
165
166
+ > Note. Since v0.9.5 you can set these tracers through Go's standard flag
167
+ > package just by adding ` flag.Parse ()` to your program. See more information
168
+ > from [Automatic Flags](#automatic-flags).
169
+
165
170
[Read the package documentation for more
166
171
information](https://pkg.go.dev/github.com/lainio/err2).
167
172
@@ -268,6 +273,8 @@ cycle. The default mode is to return an `error` value that includes a formatted
268
273
and detailed assertion violation message. A developer gets immediate and proper
269
274
feedback, allowing cleanup of the code and APIs before the release.
270
275
276
+ #### Asserters
277
+
271
278
The assert package offers a few pre-build *asserters*, which are used to
272
279
configure how the assert package deals with assert violations. The line below
273
280
exemplifies how the default asserter is set in the package.
@@ -289,6 +296,10 @@ error messages as simple as possible. And by offering option to turn additional
289
296
information on, which allows super users and developers get more technical
290
297
information when needed.
291
298
299
+ > Note. Since v0.9.5 you can set these asserters through Go's standard flag
300
+ > package just by adding ` flag.Parse ()` to your program. See more information
301
+ > from [Automatic Flags](#automatic-flags).
302
+
292
303
#### Assertion Package for Runtime Use
293
304
294
305
Following is example of use of the assert package:
@@ -351,7 +362,13 @@ stack.**
351
362
## Automatic Flags
352
363
353
364
When you are using ` err2` or ` assert` packages, i.e., just importing them, you
354
- have an option to automatically add support for Go's standard ` flag` package.
365
+ have an option to automatically support for err2 configuration flags through
366
+ Go's standard ` flag` package. See more information about err2 settings from
367
+ [Error Stack Tracing](#error-stack-tracing) and [Asserters](#asserters).
368
+
369
+ Now you can always deploy your applications and services with the simple
370
+ end-user friendly error messages and no stack traces, **but you can switch them
371
+ on when ever you need**.
355
372
356
373
Let's say you have build CLI (` your-app` ) tool with the support for Go's flag
357
374
package, and the app returns an error. Let's assume you're a developer. You can
@@ -403,15 +420,15 @@ support packages like `err2` and `glog` and their flags.
403
420
404
421
` ` ` go
405
422
PersistentPreRunE: func (cmd *cobra.Command , args []string ) (err error ) {
406
- defer err2.Handle (&err)
407
-
408
- // NOTE! Very important. Adds support for std flag pkg users: glog, err2
409
- goflag.Parse ()
410
-
411
- try.To (goflag.Set (" logtostderr" , " true" ))
412
- handleViperFlags (cmd) // local helper with envs
413
- glog.CopyStandardLogTo (" ERROR" ) // for err2
414
- return nil
423
+ defer err2.Handle (&err)
424
+
425
+ // NOTE! Very important. Adds support for std flag pkg users: glog, err2
426
+ goflag.Parse ()
427
+
428
+ try.To (goflag.Set (" logtostderr" , " true" ))
429
+ handleViperFlags (cmd) // local helper with envs
430
+ glog.CopyStandardLogTo (" ERROR" ) // for err2
431
+ return nil
415
432
},
416
433
` ` `
417
434
0 commit comments