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