import ( "fmt" "github.com/cockroachdb/cockroach/pkg/util/errorutil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/errors" ) func foo() error { return errors.WithDetail(errors.New("an error occurred"), "additional details") } func main() { if err := foo(); err != nil { log.FatalDepth(1, errorutil.MakeErrorWithContext(err, "foo failed").Error()) // Output: E1706604: foo failed: an error occurred (additional details) } }
import ( "fmt" "github.com/cockroachdb/cockroach/pkg/util/errorutil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/errors" ) func bar() error { return errors.WithDetail(errors.New("another error occurred"), "more details") } func main() { if err := bar(); err != nil { details := errorutil.GetDetail(err) fmt.Printf("details: %s\n", details) // Output: details: more details } }In this example, `bar` returns an `error` similar to the previous example. However, in this case, `errorutil.GetDetail` is used to extract the additional details from the error message and print it to the console. In both examples, the `GetDetail` function is used to extract additional details from an error message. This helps developers debug and fix issues with their code.