-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* implement errors for framework * chore: update mocks * implement errors for framework * rename contract import * add errors for session * rename location to module * chore: update mocks --------- Co-authored-by: kkumar-gcc <kkumar-gcc@users.noreply.github.com>
- Loading branch information
1 parent
2c6c7e7
commit 804ff1f
Showing
11 changed files
with
299 additions
and
18 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,11 @@ | ||
package errors | ||
|
||
// Error is the interface that wraps the basic error methods | ||
type Error interface { | ||
// Args allows setting arguments for the placeholders in the text | ||
Args(...any) Error | ||
// Error implements the error interface and formats the error string | ||
Error() string | ||
// SetModule explicitly sets the module in the error message | ||
SetModule(string) Error | ||
} |
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,63 @@ | ||
package errors | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
contractserrors "github.com/goravel/framework/contracts/errors" | ||
) | ||
|
||
type errorString struct { | ||
text string | ||
module string | ||
args []any | ||
} | ||
|
||
// New creates a new error with the provided text and optional module | ||
func New(text string, module ...string) contractserrors.Error { | ||
err := &errorString{ | ||
text: text, | ||
} | ||
|
||
if len(module) > 0 { | ||
err.module = module[0] | ||
} | ||
|
||
return err | ||
} | ||
|
||
func (e *errorString) Args(args ...any) contractserrors.Error { | ||
e.args = args | ||
return e | ||
} | ||
|
||
func (e *errorString) Error() string { | ||
formattedText := e.text | ||
|
||
if len(e.args) > 0 { | ||
formattedText = fmt.Sprintf(e.text, e.args...) | ||
} | ||
|
||
if e.module != "" { | ||
formattedText = fmt.Sprintf("[%s] %s", e.module, formattedText) | ||
} | ||
|
||
return formattedText | ||
} | ||
|
||
func (e *errorString) SetModule(module string) contractserrors.Error { | ||
e.module = module | ||
return e | ||
} | ||
|
||
func Is(err, target error) bool { | ||
return errors.Is(err, target) | ||
} | ||
|
||
func As(err error, target any) bool { | ||
return errors.As(err, &target) | ||
} | ||
|
||
func Unwrap(err error) error { | ||
return errors.Unwrap(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,12 @@ | ||
package errors | ||
|
||
var ( | ||
ErrConfigFacadeNotSet = New("config facade is not initialized") | ||
ErrJSONParserNotSet = New("JSON parser is not initialized") | ||
|
||
ErrSessionNotFound = New("session [%s] not found") | ||
ErrSessionDriverIsNotSet = New("session driver is not set") | ||
ErrSessionDriverNotSupported = New("session driver [%s] not supported") | ||
ErrSessionDriverAlreadyExists = New("session driver [%s] already exists") | ||
ErrSessionDriverExtensionFailed = New("failed to extend session [%s] driver [%v]") | ||
) |
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,5 @@ | ||
package errors | ||
|
||
var ( | ||
ModuleSession = "session" | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Oops, something went wrong.