Files
monkey/internal/object/errors.go
Chuck Smith f08b458325
Some checks failed
Build / build (push) Successful in 10m47s
Publish Image / publish (push) Failing after 33s
Test / build (push) Failing after 6m42s
optimizations
2024-04-02 14:54:08 -04:00

35 lines
861 B
Go

package object
import (
"fmt"
)
// BinaryOpError is an binary operation error usually resulting from mismatched types
type BinaryOpError struct {
left, right Object
op string
}
func (e BinaryOpError) Error() string {
return fmt.Sprintf("unsupported operator: %s %s %s", e.left.Type(), e.op, e.right.Type())
}
// NewBinaryOpError returns a new BinaryOpError
func NewBinaryOpError(left, right Object, op string) BinaryOpError {
return BinaryOpError{left, right, op}
}
// DivisionByZeroError is an error returned when dividing by zero
type DivisionByZeroError struct {
left Object
}
func (e DivisionByZeroError) Error() string {
return fmt.Sprintf("division by zero: %s", e.left)
}
// NewDivisionByZeroError returns a new DivisionByZeroError
func NewDivisionByZeroError(left Object) DivisionByZeroError {
return DivisionByZeroError{left}
}