-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move all errors into a singular repository
- Loading branch information
Showing
7 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package pkgerrors | ||
|
||
import "fmt" | ||
|
||
// BadCommanlineArgument indicates a badly formatted commandline argument | ||
type BadCommanlineArgument struct { | ||
For string | ||
Got string | ||
ExpectedFormat string | ||
} | ||
|
||
func (e *BadCommanlineArgument) Error() string { | ||
return fmt.Sprintf("BadCommanlineArgument: for %s, got '%s'; however, the expected format is '%s'", e.For, e.Got, e.ExpectedFormat) | ||
} | ||
|
||
func NewBadCommanlineArgument(where string, got string, expectedFormat string) error { | ||
return &BadCommanlineArgument{ | ||
For: where, | ||
Got: got, | ||
ExpectedFormat: expectedFormat, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package pkgerrors | ||
|
||
import "fmt" | ||
|
||
// KeyboardInputError indicates a proble sending keyboard input to OS | ||
type KeyboardInputError struct { | ||
// Refer to https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes | ||
Code int | ||
} | ||
|
||
func (e *KeyboardInputError) Error() string { | ||
return fmt.Sprintf("KeyboardInputError: Code %d", e.Code) | ||
} | ||
|
||
func NewKeyboardInputError(code int) error { | ||
return &KeyboardInputError{ | ||
Code: code, | ||
} | ||
} | ||
|
||
// MouseInputError indicates that the sending of mouse input to OS failed | ||
type MouseInputError struct { | ||
// Refer to https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes | ||
Code int | ||
} | ||
|
||
func (e *MouseInputError) Error() string { | ||
return fmt.Sprintf("MouseInputError: Code %d", e.Code) | ||
} | ||
|
||
func NewMouseInputError(code int) error { | ||
return &MouseInputError{ | ||
Code: code, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package pkgerrors | ||
|
||
import "fmt" | ||
|
||
// NotImplementedError indicates missing implementation for a given input | ||
type NotImplementedError struct { | ||
Where string | ||
Feature string | ||
} | ||
|
||
func (e *NotImplementedError) Error() string { | ||
return fmt.Sprintf("NotImplementedError: %s not implemented in %s", e.Feature, e.Where) | ||
} | ||
|
||
func NewNotImplementedError(where string, feature string) error { | ||
return &NotImplementedError{ | ||
Where: where, | ||
Feature: feature, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/benu-cloud/benu-errors | ||
|
||
go 1.20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package pkgerrors | ||
|
||
import "fmt" | ||
|
||
// UnsupportedMessageTypeError indicates an unsupported message type has been received | ||
type UnsupportedMessageTypeError struct { | ||
GotMessageType string | ||
} | ||
|
||
func (e *UnsupportedMessageTypeError) Error() string { | ||
if e.GotMessageType != "" { | ||
return fmt.Sprintf("UnsupportedMessageTypeError: message type '%s' is unsupported", e.GotMessageType) | ||
} | ||
return "UnsupportedMessageTypeError: unknown message type" | ||
} | ||
|
||
func NewUnsupportedMessageTypeError(gotMessageType string) error { | ||
return &UnsupportedMessageTypeError{ | ||
GotMessageType: gotMessageType, | ||
} | ||
} | ||
|
||
// UnmarshalError indicates error in unmarshaling message | ||
type UnmarshalError struct { | ||
Err error | ||
} | ||
|
||
func (e *UnmarshalError) Error() string { | ||
return fmt.Sprintf("UnmarshalError: %v", e.Err) | ||
} | ||
|
||
func NewUnmarshalError(err error) error { | ||
return &UnmarshalError{ | ||
Err: err, | ||
} | ||
} | ||
|
||
// UnmarshalError indicates error in marshaling message | ||
type MarshalError struct { | ||
Err error | ||
} | ||
|
||
func (e *MarshalError) Error() string { | ||
return fmt.Sprintf("MarshalError: %v", e.Err) | ||
} | ||
|
||
func NewMarshalError(err error) error { | ||
return &MarshalError{ | ||
Err: err, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package pkgerrors | ||
|
||
import "fmt" | ||
|
||
// PublishError indicates an error publishing to rabbitmq | ||
type PublishError struct { | ||
Err error | ||
} | ||
|
||
func (e *PublishError) Error() string { | ||
return fmt.Sprintf("PublishError: %v", e.Err) | ||
} | ||
|
||
func NewPublishError(err error) error { | ||
return &PublishError{ | ||
Err: err, | ||
} | ||
} | ||
|
||
// ConsumeError indicates an error consuming from rabbitmq | ||
type ConsumeError struct { | ||
Err error | ||
} | ||
|
||
func (e *ConsumeError) Error() string { | ||
return fmt.Sprintf("ConsumeError: %v", e.Err) | ||
} | ||
|
||
func NewConsumeError(err error) error { | ||
return &ConsumeError{ | ||
Err: err, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package pkgerrors | ||
|
||
import "fmt" | ||
|
||
// ! MUST MATCH ERROR CODES FROM C CODE | ||
var streamErrorCodes = map[int]string{ | ||
1: "ERROR_ENCODER_NOT_SUPPORTED", | ||
2: "ERROR_PIPELINE_ALREADY_CREATED", | ||
3: "ERROR_PIPELINE_PARSE_BAD_FORMAT", | ||
4: "ERROR_PIPELINE_BAD_STATE", | ||
5: "ERROR_PIPELINE_SET_STATE", | ||
6: "ERROR_LINKING_PEER", | ||
8: "ERROR_BAD_PEER_ID", | ||
7: "ERROR_PIPELINE_DOESNT_EXIST", | ||
9: "ERROR_BAD_SDP", | ||
} | ||
|
||
// CStreamError indicates an error from the stream C code | ||
type CStreamError struct { | ||
ErrorCode int | ||
ErrorMessage string | ||
} | ||
|
||
func (e *CStreamError) Error() string { | ||
if e.ErrorMessage == "" { | ||
errorStr, ok := streamErrorCodes[e.ErrorCode] | ||
if !ok { | ||
return fmt.Sprintf("CStreamError: got unknown error with code %d from stream", e.ErrorCode) | ||
} | ||
return fmt.Sprintf("CStreamError: got error %s with code %d from stream", errorStr, e.ErrorCode) | ||
} else { | ||
return fmt.Sprintf("CStreamError: got error '%s'", e.ErrorMessage) | ||
} | ||
} | ||
|
||
func NewCStreamError(errorCode int) error { | ||
return &CStreamError{ | ||
ErrorCode: errorCode, | ||
} | ||
} | ||
|
||
func NewCStreamErrorWithMessage(errorMessage string) error { | ||
return &CStreamError{ | ||
ErrorMessage: errorMessage, | ||
} | ||
} | ||
|
||
// StreamError indicates an error from the Go code | ||
type StreamError struct { | ||
Err error | ||
} | ||
|
||
func (e *StreamError) Error() string { | ||
return fmt.Sprintf("StreamError: %v", e.Err) | ||
} | ||
|
||
func NewStreamError(err error) error { | ||
return &StreamError{ | ||
Err: err, | ||
} | ||
} |