github.com/dnutiu/simplFT@v0.0.0-20181023061248-df4b14cdce57/server/errors.go (about) 1 package server 2 3 import "errors" 4 5 // InputError will be raised when the input given to the parser by the client is not right. 6 type InputError struct { 7 // The operation that caused the error. 8 Op string 9 // The error that occurred during the operation. 10 Err error 11 } 12 13 func (e InputError) Error() string { return "Error: " + e.Op + ": " + e.Err.Error() } 14 15 // Input Errors 16 var ( 17 InputInvalidCommand = errors.New("invalid command") 18 InputTooManyArguments = errors.New("too many arguments") 19 InputTooFewArguments = errors.New("too few arguments") 20 ) 21 22 // Command Errors represent errors that occur when the server is executing commands 23 var ( 24 GetNoBitsError = errors.New("the file/directory contains zero bits") 25 ) 26 27 type StackError struct { 28 ErrorName string 29 Err error 30 } 31 32 func (e StackError) Error() string { return e.ErrorName + ": " + e.Err.Error() } 33 34 // Stack Errors 35 var ( 36 StackInvalidTypeError = StackError{"InvalidTypeError", errors.New("invalid item type for the Stack")} 37 StackOverflowError = StackError{"StackOverflowError", errors.New("stack capacity exceeded")} 38 StackUnderflowError = StackError{"StackUnderflowError", errors.New("stack is empty")} 39 ErrStackCast = StackError{"StackCastError", errors.New("stack can't be casted to selected type")} 40 ) 41 42 type PathError struct { 43 Err error 44 } 45 46 func (e PathError) Error() string { return "Error: " + e.Err.Error() } 47 48 // PathErrors 49 var ( 50 ErrInvalidDirectoryName = PathError{errors.New("names should not contain / character")} 51 ErrNotADirectory = PathError{errors.New("file name is not a valid directory")} 52 ErrAlreadyAtBaseDirectory = PathError{errors.New("can't go past beyond root directory")} 53 ErrSlashNotAllowed = PathError{errors.New("slash is not allowed in file names")} 54 ) 55 56 // General Errors 57 var ( 58 ErrUploadServerFailure = errors.New("upload server failed to start") 59 )