More flexible parameters to New functions

This commit is contained in:
Magnus Åhall 2023-09-26 15:01:29 +02:00
parent 6fb67141fe
commit ec5422f335

11
pkg.go
View File

@ -2,7 +2,6 @@ package WrappedError
import ( import (
// Standard // Standard
"errors"
"fmt" "fmt"
"path" "path"
"runtime" "runtime"
@ -77,12 +76,14 @@ func WrapData(err error, data interface{}) error {
} }
// New creates a new wrapped error with file and line. // New creates a new wrapped error with file and line.
func New(msg string) error { func New(msg string, params ...any) error {
wrapped := create(errors.New(msg), "") err := fmt.Errorf(msg, params...)
wrapped := create(err, "")
return wrapped return wrapped
} }
func NewData(msg string, data interface{}) error { func NewData(msg string, data interface{}, params ...any) error {
wrapped := create(errors.New(msg), data) err := fmt.Errorf(msg, params...)
wrapped := create(err, data)
return wrapped return wrapped
} }