-
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.
Exposed ErrorDetail for manipulation and added some important functio…
…ns, such as PrintStackTrace() and PrintCause(), and some getters to obtain data from the structure, in addition we have a new formatting when printing the error, with full visibility of the error with debugStack.
- Loading branch information
Gabriel Cataldo
committed
Jan 26, 2024
1 parent
7403a39
commit 4442317
Showing
4 changed files
with
112 additions
and
58 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
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 |
---|---|---|
@@ -1,30 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
errors2 "errors" | ||
"github.com/GabrielHCataldo/go-errors/errors" | ||
"github.com/GabrielHCataldo/go-helper/helper" | ||
"github.com/GabrielHCataldo/go-logger/logger" | ||
) | ||
|
||
func main() { | ||
err := simple() | ||
logger.Error("simple err:", err) | ||
all() | ||
logger.Info("simple err msg:", errors.Details(err).GetMessage()) | ||
logger.Info("simple err file:", errors.Details(err).GetFile()) | ||
logger.Info("simple err line:", errors.Details(err).GetLine()) | ||
logger.Info("simple err func:", errors.Details(err).GetFuncName()) | ||
errors.Details(err).PrintCause() | ||
errors.Details(err).PrintStackTrace() | ||
is() | ||
nilErr() | ||
details(err) | ||
} | ||
|
||
func simple() error { | ||
return errors.New("error by message with any value", 2, true) | ||
} | ||
|
||
func all() { | ||
func details(err error) { | ||
errDetail := errors.Details(err) | ||
logger.Info("message:", errDetail.GetMessage()) | ||
logger.Info("file:", errDetail.GetFile()) | ||
logger.Info("line:", errDetail.GetLine()) | ||
logger.Info("funcName:", errDetail.GetFuncName()) | ||
logger.Info("debugStack:", errDetail.GetDebugStack()) | ||
logger.Info("cause:", errDetail.GetCause()) | ||
errDetail.PrintStackTrace() | ||
errDetail.PrintCause() | ||
} | ||
|
||
func nilErr() { | ||
err := errors.NewSkipCaller(2, nil) | ||
logger.Error("nilErr err:", err == nil, helper.IsNil(err)) | ||
} | ||
|
||
func is() { | ||
err2 := errors2.New("test") | ||
err := errors.New("error by message with any value", 2) | ||
logger.Error(err) | ||
err = errors.NewSkipCaller(1, "error by message with any value", 2) | ||
logger.Error(err) | ||
err = errors.New("test") | ||
target := errors.New("test") | ||
logger.Info("errors is:", errors.Is(err, target)) | ||
logger.Info("errors2 is:", errors.Is(err2, target)) | ||
logger.Info("errors is not:", errors.IsNot(err, target)) | ||
logger.Info("is error detail?", errors.IsErrorDetail(err)) | ||
file, line, funcName, message := errors.GetErrorDetails(err) | ||
logger.Info("error details:", file, line, funcName, message) | ||
logger.Info("is error detail?", errors.IsErrorDetail(err2)) | ||
} |
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