github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/yaml/error.go (about) 1 package yaml 2 3 import ( 4 "github.com/bingoohuang/gg/pkg/yaml/ast" 5 "golang.org/x/xerrors" 6 ) 7 8 var ( 9 ErrInvalidQuery = xerrors.New("invalid query") 10 ErrInvalidPath = xerrors.New("invalid path instance") 11 ErrInvalidPathString = xerrors.New("invalid path string") 12 ErrNotFoundNode = xerrors.New("node not found") 13 ErrUnknownCommentPositionType = xerrors.New("unknown comment position type") 14 ) 15 16 func ErrUnsupportedHeadPositionType(node ast.Node) error { 17 return xerrors.Errorf("unsupported comment head position for %s", node.Type()) 18 } 19 20 // IsInvalidQueryError whether err is ErrInvalidQuery or not. 21 func IsInvalidQueryError(err error) bool { 22 return xerrors.Is(err, ErrInvalidQuery) 23 } 24 25 // IsInvalidPathError whether err is ErrInvalidPath or not. 26 func IsInvalidPathError(err error) bool { 27 return xerrors.Is(err, ErrInvalidPath) 28 } 29 30 // IsInvalidPathStringError whether err is ErrInvalidPathString or not. 31 func IsInvalidPathStringError(err error) bool { 32 return xerrors.Is(err, ErrInvalidPathString) 33 } 34 35 // IsNotFoundNodeError whether err is ErrNotFoundNode or not. 36 func IsNotFoundNodeError(err error) bool { 37 return xerrors.Is(err, ErrNotFoundNode) 38 } 39 40 // IsInvalidTokenTypeError whether err is ast.ErrInvalidTokenType or not. 41 func IsInvalidTokenTypeError(err error) bool { 42 return xerrors.Is(err, ast.ErrInvalidTokenType) 43 } 44 45 // IsInvalidAnchorNameError whether err is ast.ErrInvalidAnchorName or not. 46 func IsInvalidAnchorNameError(err error) bool { 47 return xerrors.Is(err, ast.ErrInvalidAnchorName) 48 } 49 50 // IsInvalidAliasNameError whether err is ast.ErrInvalidAliasName or not. 51 func IsInvalidAliasNameError(err error) bool { 52 return xerrors.Is(err, ast.ErrInvalidAliasName) 53 }