package genji import ( "errors" "fmt" "strings" "github.com/asdine/genji/internal/scanner" ) var ( // ErrTableNotFound is returned when the targeted table doesn't exist. ErrTableNotFound = errors.New("table not found") // ErrTableAlreadyExists is returned when attempting to create a table with the // same name as an existing one. ErrTableAlreadyExists = errors.New("table already exists") // ErrIndexNotFound is returned when the targeted index doesn't exist. ErrIndexNotFound = errors.New("index not found") // ErrIndexAlreadyExists is returned when attempting to create an index with the // same name as an existing one. ErrIndexAlreadyExists = errors.New("index already exists") // ErrRecordNotFound is returned when no record is associated with the provided key. ErrRecordNotFound = errors.New("record not found") // ErrDuplicateRecord is returned when another record is already associated with a given key, primary key, // or if there is a unique index violation. ErrDuplicateRecord = errors.New("duplicate record") ) // ParseError represents an error that occurred during parsing. type ParseError struct { Message string Found string Expected []string Pos scanner.Pos } // newParseError returns a new instance of ParseError. func newParseError(found string, expected []string, pos scanner.Pos) *ParseError { return &ParseError{Found: found, Expected: expected, Pos: pos} } // Error returns the string representation of the error. func (e *ParseError) Error() string { if e.Message != "" { return fmt.Sprintf("%s at line %d, char %d", e.Message, e.Pos.Line+1, e.Pos.Char+1) } return fmt.Sprintf("found %s, expected %s at line %d, char %d", e.Found, strings.Join(e.Expected, ", "), e.Pos.Line+1, e.Pos.Char+1) }