Skip to content
Snippets Groups Projects
Select Git revision
  • c8093a14f82a97089ad47358ed0686b3913bd141
  • master default protected
  • feature/PRXS-3383-CollectionsSort
  • refactor/PRXS-3053-Files
  • feature/PRXS-3143-3235-ReferenceOptions
  • feature/PRXS-3421-ImplementNewRefAPI
  • feature/PRXS-3143-LimitReferenceFields
  • feature/PRXS-3234-FeaturePruneIdents
  • feature/3149-LocaleCodeAsID-Feature
  • PRXS-3421-RecursiveReferences
  • feature/3109-SerializeFeature
  • release/0.33
  • feature/3109-RecoverySchema
  • feature/3109-feature
  • fix/PRXS-3369-ValidateFields
  • refactor/PRXS-3306-MovePkgGroup1
  • refactor/6-pkg-refactor-expr
  • fix/PRXS-3360-TemplateBuilderPatch
  • feature/3293-MongoV2
  • feature/3272-GoVersionUp
  • feature/PRXS-3218-HideTemplateActions
  • v0.33.1
  • v0.32.0
  • v0.31.1
  • v0.31.0
  • v0.30.0
  • v0.29.0
  • v0.28.0
  • v0.27.0-alpha.1+16
  • v0.27.0-alpha.1+15
  • v0.27.0-alpha.1+14
  • v0.27.0-alpha.1+13
  • v0.27.0-alpha.1+12
  • v0.27.0-alpha.1+11
  • v0.27.0-alpha.1+10
  • v0.27.0-alpha.1+9
  • v0.27.0-alpha.1+8
  • v0.27.0-alpha.1+7
  • v0.27.0-alpha.1+6
  • v0.27.0-alpha.1+5
  • v0.27.0-alpha.1+4
41 results

errors.go

Blame
  • hint.go 1.07 KiB
    package errors
    
    import (
    	"fmt"
    	"io"
    )
    
    type ErrHint interface{ Hint() string }
    
    type withHint struct {
    	err  error
    	hint string
    }
    
    func (w *withHint) Hint() string  { return w.hint }
    func (w *withHint) Error() string { return w.err.Error() }
    func (w *withHint) Cause() error  { return w.err }
    func (w *withHint) Unwrap() error { return w.err }
    
    func (w *withHint) Format(s fmt.State, verb rune) {
    	switch verb {
    	case 'v':
    		if s.Flag('+') {
    			fmt.Fprintf(s, "%+v", w.Cause())
    			fmt.Fprintf(s, "\nerror hint: %s", w.hint)
    			return
    		}
    		fallthrough
    	case 's':
    		io.WriteString(s, w.Error())
    	case 'q':
    		fmt.Fprintf(s, "%q", w.Error())
    	}
    }
    
    func WithHint(err error, hint string) error {
    	if err == nil {
    		return nil
    	}
    	return &withHint{err: err, hint: hint}
    }
    
    func WithHintf(err error, format string, args ...interface{}) error {
    	if err == nil {
    		return nil
    	}
    	return &withHint{err: err, hint: fmt.Sprintf(format, args...)}
    }
    
    func GetHint(err error) string {
    	for e := err; e != nil; e = Unwrap(e) {
    		if errDetail, ok := e.(ErrHint); ok {
    			return errDetail.Hint()
    		}
    	}
    	return ""
    }