Skip to content

Commit c0b6cd8

Browse files
committed
all: use errors.New instead of fmt.Errorf where appropriate
If there are no %-style directives, using errors.New is preferable. Acked-by: Tom Hromatka <[email protected]> Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 444e638 commit c0b6cd8

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

seccomp.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package seccomp
88

99
import (
10+
"errors"
1011
"fmt"
1112
"os"
1213
"runtime"
@@ -245,8 +246,8 @@ const (
245246
)
246247

247248
// ErrSyscallDoesNotExist represents an error condition where
248-
// libseccomp is unable to resolve the syscall
249-
var ErrSyscallDoesNotExist = fmt.Errorf("could not resolve syscall name")
249+
// libseccomp is unable to resolve the syscall.
250+
var ErrSyscallDoesNotExist = errors.New("could not resolve syscall name")
250251

251252
const (
252253
// Userspace notification response flags
@@ -556,7 +557,7 @@ func MakeCondition(arg uint, comparison ScmpCompareOp, values ...uint64) (ScmpCo
556557
} else if len(values) > 2 {
557558
return condStruct, fmt.Errorf("conditions can have at most 2 arguments (%d given)", len(values))
558559
} else if len(values) == 0 {
559-
return condStruct, fmt.Errorf("must provide at least one value to compare against")
560+
return condStruct, errors.New("must provide at least one value to compare against")
560561
}
561562

562563
condStruct.Argument = arg
@@ -611,7 +612,7 @@ func NewFilter(defaultAction ScmpAction) (*ScmpFilter, error) {
611612

612613
fPtr := C.seccomp_init(defaultAction.toNative())
613614
if fPtr == nil {
614-
return nil, fmt.Errorf("could not create filter")
615+
return nil, errors.New("could not create filter")
615616
}
616617

617618
filter := new(ScmpFilter)
@@ -695,7 +696,7 @@ func (f *ScmpFilter) Merge(src *ScmpFilter) error {
695696
defer src.lock.Unlock()
696697

697698
if !src.valid || !f.valid {
698-
return fmt.Errorf("one or more of the filter contexts is invalid or uninitialized")
699+
return errors.New("one or more of the filter contexts is invalid or uninitialized")
699700
}
700701

701702
// Merge the filters

seccomp_internal.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func ensureSupportedVersion() error {
340340
func getAPI() (uint, error) {
341341
api := C.seccomp_api_get()
342342
if api == 0 {
343-
return 0, fmt.Errorf("API level operations are not supported")
343+
return 0, errors.New("API level operations are not supported")
344344
}
345345

346346
return uint(api), nil
@@ -351,7 +351,7 @@ func setAPI(api uint) error {
351351
if retCode := C.seccomp_api_set(C.uint(api)); retCode != 0 {
352352
e := errRc(retCode)
353353
if e == syscall.EOPNOTSUPP {
354-
return fmt.Errorf("API level operations are not supported")
354+
return errors.New("API level operations are not supported")
355355
}
356356

357357
return fmt.Errorf("could not set API level: %w", e)
@@ -412,7 +412,7 @@ func (f *ScmpFilter) setFilterAttr(attr scmpFilterAttr, value C.uint32_t) error
412412
// Wrapper for seccomp_rule_add_... functions
413413
func (f *ScmpFilter) addRuleWrapper(call ScmpSyscall, action ScmpAction, exact bool, length C.uint, cond C.scmp_cast_t) error {
414414
if length != 0 && cond == nil {
415-
return fmt.Errorf("null conditions list, but length is nonzero")
415+
return errors.New("null conditions list, but length is nonzero")
416416
}
417417

418418
var retCode C.int
@@ -431,7 +431,7 @@ func (f *ScmpFilter) addRuleWrapper(call ScmpSyscall, action ScmpAction, exact b
431431
case syscall.EPERM, syscall.EACCES:
432432
return errDefAction
433433
case syscall.EINVAL:
434-
return fmt.Errorf("two checks on same syscall argument")
434+
return errors.New("two checks on same syscall argument")
435435
default:
436436
return e
437437
}
@@ -456,7 +456,7 @@ func (f *ScmpFilter) addRuleGeneric(call ScmpSyscall, action ScmpAction, exact b
456456
} else {
457457
argsArr := C.make_arg_cmp_array(C.uint(len(conds)))
458458
if argsArr == nil {
459-
return fmt.Errorf("error allocating memory for conditions")
459+
return errors.New("error allocating memory for conditions")
460460
}
461461
defer C.free(argsArr)
462462

@@ -496,7 +496,7 @@ func sanitizeAction(in ScmpAction) error {
496496
}
497497

498498
if inTmp != ActTrace && inTmp != ActErrno && (in&0xFFFF0000) != 0 {
499-
return fmt.Errorf("highest 16 bits must be zeroed except for Trace and Errno")
499+
return errors.New("highest 16 bits must be zeroed except for Trace and Errno")
500500
}
501501

502502
return nil

0 commit comments

Comments
 (0)