110 Commits

Author SHA1 Message Date
Dave Cheney
645ef00459 doc tweaks v0.8.0 2016-09-29 11:48:01 +10:00
Dave Cheney
7433cb070c fix line numbers in fmt tests 2016-09-29 11:32:15 +10:00
Nick Miyake
3a4fafe48b Fix comment on WithMessage function (#86) 2016-09-29 11:32:15 +10:00
fabstu
1398fbcad1 tests: fixed tests on 1.4. 2016-09-29 11:32:15 +10:00
fabstu
162fea7c06 tests: added recursively trying out combinations of calls for %+v. 2016-09-29 11:32:15 +10:00
fabstu
542b81d67c minor: refactored small loop 2016-09-29 11:32:15 +10:00
fabstu
011399d349 Add WithStack and WithMessage tests
Adds testFormatCompleteCompare as additional testing func.

The new function takes a string slice as "want", wherein
stacktraces and non-stacktrace messages are discerned by
strings.ContainsAny(want[i], "\n").

For example usage, see TestFormatWithStack & TestFormatWithMessage.
2016-09-29 11:32:15 +10:00
Dave Cheney
4f8d1cf2a2 Revert "Remove WithStack and WithMessage public functions"
This reverts commit 1b876e063eebebbcbab83aafa8bc631edef98fff.
2016-09-29 11:32:15 +10:00
Thomas de Zeeuw
a887431f7f Add Go 1.7.1 to Travis (#85) 2016-09-16 21:02:12 +10:00
Nick Craig-Wood
17b591df37 Fix the %q format for errors so it puts "" around the output (#83) v0.7.1 2016-08-22 10:00:10 +01:00
Dave Cheney
a22138067a remove incorrect comment 2016-08-08 15:55:40 +10:00
Dave Cheney
9cadab9279 Merge pull request #81 from pkg/withMessage-withStack
Refactor withMessage/withStack
2016-08-08 14:49:31 +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
Paul Robins
2a9be18ecd Modify TestTrimGOPATH to ensure tests pass while vendored (#78) 2016-08-01 20:26:19 +10:00
Daniel Theophanes
1d2e60385a errors: add a benchmark comparing stack trace performance (#74)
Fixes #72
2016-07-24 12:43:27 +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
Vincent Batts
a2d6902c6d LICENSE: remove trailing newline (#61)
Discovered while vendoring this repo, and having a check for trailing
whitespace. (e.g. `git show --check 45e9319`)

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-06-28 08:23:52 +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) v0.7.0 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
d4b5735536 update README, reduce duplication with godoc 2016-06-11 15:59:14 +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
297d9e8969 fix error in Stacktrace example 2016-06-11 15:49:40 +10:00
Dave Cheney
a5b220e0c6 Introduce errors.Stacktrace (#48)
* Introduce errors.Stacktrace

Introduce a new type to replace the unnamed return value from
`Stacktrace()`. `Stacktrace` implements `fmt.Formatter` and currently
replicates the default behaviour of printing a `[]Frame`.

In a future PR the values of `%+v` and `%#v` will be extended to
implement a more readable stacktrace.
2016-06-10 14:10:18 +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
5776abf3b9 Remove deprecated Stack() []uintptr interface (#45)
* Remove deprecated Stack() []uintptr interface

* move TestStack to TestStacktrace
2016-06-10 00:48:07 +10:00
Matt Singletary
89edb63f9e Fix typo in comment (#46) 2016-06-10 00:47:22 +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
Anthony Fok
4ffae16a01 Correct the licence reference in README.md (#42)
Using the short identifier specified by SPDX
at https://spdx.org/licenses/BSD-2-Clause

Fixes #41
2016-06-09 10:57:48 +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
e23d6edfd2 extract funcname helper, and add test 2016-06-08 19:21:37 +10:00
Dave Cheney
f22595b332 fix Stacktrace example 2016-06-07 18:47:44 +10:00
Dave Cheney
2c9da72fa5 fix typos v0.6.0 2016-06-07 17:26:48 +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
f45f2b7903 add appveyor.yml (#36) 2016-06-07 07:41:47 +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