Commit Graph

70 Commits (e9933c1c09fbbc45a9af4788f95d672c4e90054d)

Author SHA1 Message Date
Dave Cheney 937e8c5528 gofmt -w
Signed-off-by: Dave Cheney <dave@cheney.net>
2019-01-05 19:54:25 +11:00
Dave Cheney c1bc528f85
Merge branch 'master' into patch-1 2019-01-05 19:50:32 +11:00
Tariq Ibrahim ba968bfe8b gofmt -w errors.go (#179) 2019-01-03 17:52:24 +11:00
Bjørn Erik Pedersen 6ed0a2e59e
Fix StackTrace print example 2018-10-14 16:58:47 +02:00
Steven E. Harris 2233dee583 Copyedit the package documentation (#135)
Remove spurious words, add missing words, and smooth out a few
sentences.
2018-10-08 15:53:15 +11:00
Dariusz Jedrzejczyk e981d1a2c5 Add WithMessagef function (#118)
WithMessagef utility function to accompany WithMessage, similar to
exiting Wrapf function accompanying Wrap.
2018-10-08 15:50:16 +11:00
Eldar Rakhimberdin c059e472ca fixed spelling (#156) 2018-09-11 16:21:13 +10:00
Dave Cheney 645ef00459 doc tweaks 2016-09-29 11:48:01 +10:00
Nick Miyake 3a4fafe48b Fix comment on WithMessage function (#86) 2016-09-29 11:32:15 +10:00
Dave Cheney 4f8d1cf2a2 Revert "Remove WithStack and WithMessage public functions"
This reverts commit 1b876e063e.
2016-09-29 11:32:15 +10:00
Nick Craig-Wood 17b591df37 Fix the %q format for errors so it puts "" around the output (#83) 2016-08-22 10:00:10 +01:00
Dave Cheney a22138067a remove incorrect comment 2016-08-08 15:55:40 +10:00
Dave Cheney 1b876e063e Remove WithStack and WithMessage public functions
The refactoring to use withStack and withMessage types is useful enough
to land indepdently of exposing these helpers publically.
2016-08-08 14:39:38 +10:00
Dave Cheney 777ed74de5 Destructure Wrap{,f} into WithStack(WithMessage(err, msg))
Introduces WithMessage as well as errors.fundamental, errors.withMessage
and errors.withStack internal types.

Adjust tests for the new wrapped format when combining fundamental and
wrapped errors.
2016-08-08 14:31:22 +10:00
Dave Cheney 785921b1c1 Destructure New/Errorf
Destructure New/Errorf into two components, a call to the stdlib
errors.New or fmt.Errorf to generate a _fundamental_ error, and then a
call to withStack to attach a stack trace to the message.
2016-08-08 14:31:22 +10:00
Alexey Palazhchenko cc5fbb72d9 Documentation improvements (#69)
* Add install instructions.

* Document that causer and stackTracer are stable.
2016-07-19 19:13:40 +10:00
Jon Gillham d62207b3dc Capitalise first letter of trace. (#60) 2016-06-27 12:13:31 +10:00
Darshan Shaligram cbd18b5440 Fix %q format for wrapped errors (#58)
Not handling the %q format causes logrus to log empty error strings for
wrapped errors where x.Error() contains spaces or other quoteworthy
characters.

For reference, the logrus formatter does this:
https://github.com/Sirupsen/logrus/blob/master/text_formatter.go#L154
2016-06-22 11:00:19 +10:00
Dave Cheney 0bc61eb85b Wrapper errors now print full stacktrace (#57) 2016-06-19 14:34:20 +10:00
Dave Cheney 494e70f762 Rename StackTrace interface to stacktracer in docs and examples (#56) 2016-06-16 17:40:57 +10:00
Uwe Dauernheim 01fa4104b9 Align code example documentation (#52) 2016-06-13 12:17:47 +10:00
Dave Cheney 73d71e4a6a Rename Stacktrace to StackTrace (#51)
Fixes #50
2016-06-13 11:11:14 +10:00
Dave Cheney 784931b43c rename errors.New parameter to message 2016-06-13 10:58:08 +10:00
Dave Cheney 9a4f977a05 document extended format 2016-06-11 23:12:34 +10:00
Dave Cheney 7896481a53 Extended stacktrace output (#49)
* Extended stacktrace output

* Make format tests less sensitive to sourcecode prefix

* use testFormatRegexp for all Sprintf tests

* replace output test with sample output

* work around the different fn.Name format in go 1.4

* fix windows tests when there is a drive letter in the source path
2016-06-11 23:04:57 +10:00
Dave Cheney 7f46da032a update godoc 2016-06-11 15:57:15 +10:00
Dave Cheney c5fe904864 update godoc 2016-06-11 15:54:49 +10:00
Dave Cheney d7cdef1704 Remove Fprint (#47) 2016-06-10 11:53:11 +10:00
Dave Cheney 874c0ec5b0 Reimplement Fprint in terms of fmt.Fprintf (#44)
This PR follows on from #40 completely implementing Fprint in terms of
fmt.Fprintf. This will be the final PR before Fprint is removed.
2016-06-10 08:39:59 +10:00
Dave Cheney 3dc37da2ca Reverse the order of Fprint output (#43)
Fprint should match the stack output, innermost error first.

It probably doesn't matter as Fprint is going away.
2016-06-09 20:02:11 +10:00
Dave Cheney c0c662e216 Use fmt.Formatter throughout (#40)
* Use fmt.Formatter throughout

Replace Fprintf with fmt.Formatter logic on various types. This
effectively guts Fprint to be just a recursive call down the err.Cause
chain. The next step will be to move this recursive logic into
wrapper.Format.

This change necessitates adding types for the error impls returned from
New and Errorf, and Wrap and Wrapf, respectively. The name of the latter
type is acceptable, the former is not and alternative suggestions are
encouraged.

- Remove cause.Format
- Added fmt.Formatter tests. The location is temporary, once this PR is merged and Fprint removed
they will be merged into errors_test.go
2016-06-09 16:45:08 +10:00
Dave Cheney 2af433a3bd Remove Message interface (#39)
Replace Message with a Format method on cause. This simplifies Fprint as
well as removing one interface method from Wrap/Wrapf error impls.
2016-06-08 20:37:09 +10:00
Dave Cheney d146efd52a relocate cause 2016-06-08 20:25:18 +10:00
Dave Cheney 19140ea8c4 Remove deprecated Location interface 2016-06-08 19:34:10 +10:00
Dave Cheney 3cdd33210d Introduce Stacktrace and Frame (#37)
* Introduce Stacktrace and Frame

This PR is a continuation of a series aimed at exposing the stack trace
information embedded in each error value. The secondary effect is to
deprecated the `Fprintf` helper.

Taking cues from from @chrishines' `stack` package this PR introduces a
new interface `Stacktrace() []Frame` and a `Frame` type, similar in
function to the `runtime.Frame` type (although lacking its iterator
type). Each `Frame` implemnts `fmt.Formatter` allowing it to print
itself.

The older `Location` interface is still supported but also deprecated.
2016-06-07 14:23:05 +10:00
Dave Cheney b700c3e918 fix typo 2016-06-06 20:27:34 +10:00
Dave Cheney 431554f80b Remove errors.wrap helper
`errors.wrap` existed to avoid the conflict between the type,
`errors.cause` and the formal parameter `cause`. The parameter was
renamed to err in #32 so there is no need for the helper.
2016-05-26 15:24:04 +10:00
Mat Ryer 936b5d744d renamed `cause` argument to `err` - fixes #32 (#33) 2016-05-25 09:59:37 +10:00
Dave Cheney e8c21980b6 Make errors.stack comparable (#30)
Fixed #29

errors.New, etc values are not expected to be compared by value but
the change in errors#27 made them incomparable. Assert that various
kinds of errors have a functional equality operator, even if the
result of that equality is always false.
2016-05-24 12:36:43 +10:00
Dave Cheney cc157cd49f Store the stack of the caller to New, Errorf, Wrap and Wrapf (#27)
Store up to 32 stack frames for the caller to New, Errorf, Wrap, and
Wrapf.
2016-05-23 18:47:43 +10:00
Dave Cheney 567ccaadc6 Split stack.Location into a private helper 2016-05-23 17:36:45 +10:00
Dave Cheney 80cce0ee9b Rename errors.location to errors.stack (#26) 2016-05-23 17:32:36 +10:00
Dave Cheney daa1017c6f Refactor errors.location to be a stack of callers (#25)
Refactory errors.location to be a stack of callers rather than the
topmost caller. This is in perparation for storing the entire error
stack inside topmost error.
2016-05-23 17:10:14 +10:00
Dave Cheney d814416a46 update package description (#24) 2016-05-11 07:41:07 +10:00
Dave Cheney 01fff4b066 Remove errors.Print (#23)
errors.Print had a number of problems. Firstly, it was hard coded to
print to os.Stderr, which made it difficult to test, and hard to write
an example test for. Secondly, comments made in issue #20 make it clear
that helpers need to have a high bar for inclusion in this package, and
something that wrapped errors.Fprint in a way that was hard to test
fails that bar.

So, Remove errors.Print, which frees the identifier for being reused
later, and reduces the size of the package.
2016-05-10 11:02:00 +10:00
Jud White 0d62637d04 errors.go: "nor" -> "not" (typo fix) (#17) 2016-05-04 06:53:04 +08:00
Santiago Corredoira Lascaray 7a0abd8f63 Add Errorf (#14) 2016-04-30 08:38:57 +10:00
Dave Cheney cd6e0b425d address spelling mistakes. Thanks @seh 2016-04-27 10:39:47 +10:00
Dave Cheney 7efa461bd3 Fix spelling mistake in comment 2016-04-26 12:27:40 +10:00
Dave Cheney 3612ec480e Remove the errors.e type (#11)
* rename loc type to location

* move locationer interface inside Fprint, rename to location

* refactor Wrap/Wrapf into helper method

* remove errors.e type, compose an anon struct in wrap and add a Message() interface method to extract the cause message
2016-04-26 12:25:34 +10:00