added new function, FormatFatal

This commit is contained in:
Nils Stinnesbeck 2023-03-22 16:36:16 +01:00
parent d00b90b00b
commit 0a512f8d47
Signed by: nils
GPG Key ID: 9AEBF097A4042590
2 changed files with 9 additions and 2 deletions

View File

@ -1,8 +1,15 @@
package errorhandler
import "fmt"
import (
"fmt"
"log"
)
// FormatError formats text and the error in a standardized way
func FormatError(text string, err error) error {
return fmt.Errorf(fmt.Sprintf("%s, error is:\n\t-> %s", text, err))
}
func FormatFatal(text string, err error) {
log.Fatalf(fmt.Sprintf("%s, error is:\n\t-> %s", text, err))
}

View File

@ -6,7 +6,7 @@ import (
"testing"
)
func TestCheck(t *testing.T) {
func TestFormatError(t *testing.T) {
text := "text before error"
err := "test error"