You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,14 +3,14 @@ A modern error handling package to add additional structured fields to errors. T
3
3
[only handle errors once rule](https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully) while not losing context where the error occurred.
4
4
5
5
*`errors.Wrap(err, "while reading")` includes a stack trace so logging can report the exact location where
6
-
the error occurred. (you can also call `Wrapf()`)
6
+
the error occurred. *You can also call `Wrapf()`*
7
7
*`errors.WithStack(err)` for when you don't need a message, just a stack trace to where the error occurred.
8
8
*`errors.WithFields{"fileName": fileName}.Wrap(err, "while reading")` Attach additional fields to the error and a stack
9
-
trace to give structured logging as much context to the error as possible. (you can also call `Wrapf()`)
9
+
trace to give structured logging as much context to the error as possible. *You can also call `Wrapf()`*
10
10
*`errors.WithFields{"fileName": fileName}.WithStack(err)` for when you don't need a message, just a stack
11
11
trace and some fields attached.
12
12
*`errors.WithFields{"fileName": fileName}.Error("while reading")` when you want to create a string error with
13
-
some fields attached. (you can also call `Errorf()`)
13
+
some fields attached. *You can also call `Errorf()`*
14
14
15
15
### Extract structured data from wrapped errors
16
16
Convenience functions to extract all stack and field information from the error.
@@ -43,6 +43,10 @@ If you are working at mailgun and are using scaffold; using `logrus.WithError(er
43
43
automatically retrieve the fields attached to the error and index them into our logging system as separate
44
44
searchable fields.
45
45
46
+
## Perfect for passing additional information to http handler middleware
47
+
If you have custom http middleware for handling unhandled errors, this is an excellent way
48
+
to easily pass additional information about the request up to the error handling middleware.
49
+
46
50
## Adding structured fields to an error
47
51
Wraps the original error while providing structured field data
0 commit comments