error.go raw

   1  package yaml
   2  
   3  import (
   4  	"github.com/goccy/go-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  	ErrInvalidCommentMapValue     = xerrors.New("invalid comment map value. it must be not nil value")
  15  )
  16  
  17  func ErrUnsupportedHeadPositionType(node ast.Node) error {
  18  	return xerrors.Errorf("unsupported comment head position for %s", node.Type())
  19  }
  20  
  21  // IsInvalidQueryError whether err is ErrInvalidQuery or not.
  22  func IsInvalidQueryError(err error) bool {
  23  	return xerrors.Is(err, ErrInvalidQuery)
  24  }
  25  
  26  // IsInvalidPathError whether err is ErrInvalidPath or not.
  27  func IsInvalidPathError(err error) bool {
  28  	return xerrors.Is(err, ErrInvalidPath)
  29  }
  30  
  31  // IsInvalidPathStringError whether err is ErrInvalidPathString or not.
  32  func IsInvalidPathStringError(err error) bool {
  33  	return xerrors.Is(err, ErrInvalidPathString)
  34  }
  35  
  36  // IsNotFoundNodeError whether err is ErrNotFoundNode or not.
  37  func IsNotFoundNodeError(err error) bool {
  38  	return xerrors.Is(err, ErrNotFoundNode)
  39  }
  40  
  41  // IsInvalidTokenTypeError whether err is ast.ErrInvalidTokenType or not.
  42  func IsInvalidTokenTypeError(err error) bool {
  43  	return xerrors.Is(err, ast.ErrInvalidTokenType)
  44  }
  45  
  46  // IsInvalidAnchorNameError whether err is ast.ErrInvalidAnchorName or not.
  47  func IsInvalidAnchorNameError(err error) bool {
  48  	return xerrors.Is(err, ast.ErrInvalidAnchorName)
  49  }
  50  
  51  // IsInvalidAliasNameError whether err is ast.ErrInvalidAliasName or not.
  52  func IsInvalidAliasNameError(err error) bool {
  53  	return xerrors.Is(err, ast.ErrInvalidAliasName)
  54  }
  55