Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions middleware/recoverer.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func PrintPrettyStack(rvr interface{}) {
printPrettyStack(rvr, true)
}

// printPrettyStack prints a formatted stack trace to stderr. When useColor is
// false, ANSI colour codes are suppressed, which is useful for terminals that
// do not support them (e.g. on Windows) or when output is being captured.
func printPrettyStack(rvr interface{}, useColor bool) {
debugStack := debug.Stack()
s := prettyStack{}
Expand Down
7 changes: 7 additions & 0 deletions middleware/recoverer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ func TestRecoverer(t *testing.T) {
}

func TestRecovererNoColor(t *testing.T) {
// Force IsTTY so cW would emit color codes if useColor were true; this is
// what makes the assertion below a real regression guard rather than a
// no-op on non-TTY test runners (e.g. CI).
oldIsTTY := IsTTY
IsTTY = true
defer func() { IsTTY = oldIsTTY }()

oldRecovererErrorWriter := recovererErrorWriter
defer func() { recovererErrorWriter = oldRecovererErrorWriter }()
buf := &bytes.Buffer{}
Expand Down
Loading