Commit Graph

22 Commits (master)

Author SHA1 Message Date
Adrian Perez 004deef562
remove unnecessary use of fmt.Sprintf (#217)
* remove unnecessary use of fmt.Sprintf
2020-01-03 13:36:54 +01: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
Jon Gillham d62207b3dc Capitalise first letter of trace. (#60) 2016-06-27 12:13:31 +10:00
Dave Cheney 494e70f762 Rename StackTrace interface to stacktracer in docs and examples (#56) 2016-06-16 17:40:57 +10:00
Dave Cheney 73d71e4a6a Rename Stacktrace to StackTrace (#51)
Fixes #50
2016-06-13 11:11:14 +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 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
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
Dave Cheney f22595b332 fix Stacktrace example 2016-06-07 18:47:44 +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
Santiago Corredoira Lascaray 7a0abd8f63 Add Errorf (#14) 2016-04-30 08:38:57 +10:00
Umair Idris 9a179122f1 Add Wrapf 2016-04-25 00:31:25 -04:00
Dave Cheney a15b27b2bf fix second errors.New example 2016-04-22 20:15:46 +09:00
Dave Cheney 258d1265c4 skip tests on tip 2016-04-22 19:19:39 +09:00
Dave Cheney 4df5f1c4b6 added example, fixed tests 2016-04-22 19:13:47 +09:00
Dave Cheney a7f2be0bfe added godoc 2016-04-22 19:10:04 +09:00
Dave Cheney f5db181ac2 more examples 2016-04-22 17:46:16 +09:00
Dave Cheney b402999421 more examples 2016-04-22 17:40:16 +09:00
Dave Cheney 1e412a1049 Added New and Cause methods. 2015-12-27 15:19:49 +01:00