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 5package xerrors 6 7import "fmt" 8 9// errorString is a trivial implementation of error. 10type errorString struct { 11 s string 12 frame Frame 13} 14 15// New returns an error that formats as the given text. 16// 17// The returned error contains a Frame set to the caller's location and 18// implements Formatter to show this information when printed with details. 19func New(text string) error { 20 return &errorString{text, Caller(1)} 21} 22 23func (e *errorString) Error() string { 24 return e.s 25} 26 27func (e *errorString) Format(s fmt.State, v rune) { FormatError(e, s, v) } 28 29func (e *errorString) FormatError(p Printer) (next error) { 30 p.Print(e.s) 31 e.frame.Format(p) 32 return nil 33} 34