Debian Codegraph @

errors/errors.go

raw symbols SCIP
1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Package errors implements functions to manipulate errors.
6 //
7 // This package implements the Go 2 draft designs for error inspection and printing:
8 //
9 // https://go.googlesource.com/proposal/+/master/design/go2draft.md
10 //
11 // This is an EXPERIMENTAL package, and may change in arbitrary ways without notice.
12 package errors
13
14 // errorString is a trivial implementation of error.
15 type errorString struct {
16 s string
17 frame Frame
18 }
19
20 // New returns an error that formats as the given text.
21 //
22 // The returned error embeds a Frame set to the caller's location and implements
23 // Formatter to show this information when printed with details.
24 func New(text string) error {
25 return &errorString{text, Caller(1)}
26 }
27
28 func (e *errorString) Error() string {
29 return e.s
30 }
31
32 func (e *errorString) FormatError(p Printer) (next error) {
33 p.Print(e.s)
34 e.frame.Format(p)
35 return nil
36 }