Skip to content

%+v is too verbose #5

@tebeka

Description

@tebeka

When printing error which have causes with %+v verb, you'll get the stack trace several times.

main.go

package main

import (
	"fmt"

	"github.com/friendsofgo/errors"
)

func a() error {
	return errors.Errorf("a")
}

func b() error {
	err := a()
	return errors.Wrap(err, "b")
}

func c() error {
	err := b()
	return errors.Wrap(err, "c")
}

func main() {
	err := c()
	fmt.Printf("%+v\n", err)
}

Running

$ go run main.go
a
main.a
	/tmp/pe/main.go:10
main.b
	/tmp/pe/main.go:14
main.c
	/tmp/pe/main.go:19
main.main
	/tmp/pe/main.go:24
runtime.main
	/opt/go/src/runtime/proc.go:203
runtime.goexit
	/opt/go/src/runtime/asm_amd64.s:1357
b
main.b
	/tmp/pe/main.go:15
main.c
	/tmp/pe/main.go:19
main.main
	/tmp/pe/main.go:24
runtime.main
	/opt/go/src/runtime/proc.go:203
runtime.goexit
	/opt/go/src/runtime/asm_amd64.s:1357
c
main.c
	/tmp/pe/main.go:20
main.main
	/tmp/pe/main.go:24
runtime.main
	/opt/go/src/runtime/proc.go:203
runtime.goexit
	/opt/go/src/runtime/asm_amd64.s:1357

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions