-
Notifications
You must be signed in to change notification settings - Fork 6
/
make_error.go
26 lines (22 loc) · 879 Bytes
/
make_error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// -----------------------------------------------------------------------------
// github.com/balacode/udpt /[make_error.go]
// (c) balarabe@protonmail.com License: MIT
// -----------------------------------------------------------------------------
package udpt
import (
"errors"
"fmt"
"regexp"
"strings"
)
// makeError returns a new error instance by joining 'id' and 'a'.
// The ID is formatted as a 6-digit hex string. e.g. "0xE12345"
func makeError(id uint32, a ...interface{}) error {
rx := regexp.MustCompile(`ERROR 0x[0-9a-fA-F]*: `)
m := joinArgs("", a...)
m = string(rx.ReplaceAll([]byte(m), []byte("")))
m = fmt.Sprintf("ERROR 0x%06X: ", id) + m
m = strings.TrimSpace(m)
return errors.New(m)
} // makeError
// end