Restore working state
This commit is contained in:
parent
f9cdbe5ac9
commit
3cbe45c420
7 changed files with 55 additions and 34 deletions
26
utils/errors.go
Normal file
26
utils/errors.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func WrapErrWithLog(err error, msg, log string) error {
|
||||
return errors.Wrapf(err, "%v %v", msg, GetLogErrMsg(log))
|
||||
}
|
||||
|
||||
func GetLogErrMsg(s string) string {
|
||||
logToInclude := strings.ReplaceAll(s, "\n", "\\n")
|
||||
logToInclude = strings.TrimSuffix(logToInclude, "\\n")
|
||||
logToInclude = ClearUnprintableChars(logToInclude, false)
|
||||
|
||||
origLogLen := len(logToInclude)
|
||||
const maxLogLen = 256
|
||||
if origLogLen > maxLogLen {
|
||||
logToInclude = fmt.Sprintf("[%v chars trimmed]", origLogLen) + logToInclude[len(logToInclude)-maxLogLen:]
|
||||
}
|
||||
|
||||
return fmt.Sprintf("(log: '%v')", logToInclude)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue