simplFT/server/errors.go

60 lines
1.8 KiB
Go
Raw Permalink Normal View History

2017-10-20 15:08:25 +00:00
package server
import "errors"
2017-10-28 16:02:26 +00:00
// InputError will be raised when the input given to the parser by the client is not right.
2017-10-20 15:08:25 +00:00
type InputError struct {
// The operation that caused the error.
2017-10-28 16:02:26 +00:00
Op string
2017-10-20 15:08:25 +00:00
// The error that occurred during the operation.
Err error
}
2017-10-28 16:02:26 +00:00
func (e InputError) Error() string { return "Error: " + e.Op + ": " + e.Err.Error() }
2017-10-20 15:08:25 +00:00
2017-10-20 15:25:47 +00:00
// Input Errors
2017-10-20 15:08:25 +00:00
var (
2017-10-29 13:01:45 +00:00
InputInvalidCommand = errors.New("invalid command")
InputTooManyArguments = errors.New("too many arguments")
InputTooFewArguments = errors.New("too few arguments")
2017-10-20 15:08:25 +00:00
)
2017-10-28 16:02:26 +00:00
// Command Errors represent errors that occur when the server is executing commands
var (
2017-10-29 13:01:45 +00:00
GetNoBitsError = errors.New("the file/directory contains zero bits")
2017-10-28 16:02:26 +00:00
)
type StackError struct {
ErrorName string
Err error
}
func (e StackError) Error() string { return e.ErrorName + ": " + e.Err.Error() }
// Stack Errors
var (
2017-10-29 13:01:45 +00:00
StackInvalidTypeError = StackError{"InvalidTypeError", errors.New("invalid item type for the Stack")}
StackOverflowError = StackError{"StackOverflowError", errors.New("stack capacity exceeded")}
StackUnderflowError = StackError{"StackUnderflowError", errors.New("stack is empty")}
2017-11-08 20:18:23 +00:00
ErrStackCast = StackError{"StackCastError", errors.New("stack can't be casted to selected type")}
2017-10-28 16:02:26 +00:00
)
2017-10-29 16:59:03 +00:00
type PathError struct {
Err error
}
func (e PathError) Error() string { return "Error: " + e.Err.Error() }
2017-10-29 16:59:03 +00:00
// PathErrors
var (
ErrInvalidDirectoryName = PathError{errors.New("names should not contain / character")}
ErrNotADirectory = PathError{errors.New("file name is not a valid directory")}
ErrAlreadyAtBaseDirectory = PathError{errors.New("can't go past beyond root directory")}
ErrSlashNotAllowed = PathError{errors.New("slash is not allowed in file names")}
2017-10-29 16:59:03 +00:00
)
// General Errors
var (
ErrUploadServerFailure = errors.New("upload server failed to start")
)