Skip to content

Commit b5d37cd

Browse files
committed
all: use errors.New instead of fmt.Errorf
...if there are no %-style arguments. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 63f3dbc commit b5d37cd

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

daemon/watchdog.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package daemon
1616

1717
import (
18+
"errors"
1819
"fmt"
1920
"os"
2021
"strconv"
@@ -54,7 +55,7 @@ func SdWatchdogEnabled(unsetEnvironment bool) (time.Duration, error) {
5455
return 0, fmt.Errorf("error converting WATCHDOG_USEC: %w", err)
5556
}
5657
if s <= 0 {
57-
return 0, fmt.Errorf("error WATCHDOG_USEC must be a positive number")
58+
return 0, errors.New("error WATCHDOG_USEC must be a positive number")
5859
}
5960
interval := time.Duration(s) * time.Microsecond
6061

login1/dbus.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package login1
1717

1818
import (
1919
"context"
20+
"errors"
2021
"fmt"
2122
"os"
2223
"strconv"
@@ -186,7 +187,7 @@ func (c *Conn) GetActiveSession() (dbus.ObjectPath, error) {
186187
// GetSessionUser may be used to get the user of specific session
187188
func (c *Conn) GetSessionUser(sessionPath dbus.ObjectPath) (*User, error) {
188189
if len(sessionPath) == 0 {
189-
return nil, fmt.Errorf("empty sessionPath")
190+
return nil, errors.New("empty sessionPath")
190191
}
191192

192193
activeSessionObj := c.conn.Object(dbusDest, sessionPath)
@@ -224,7 +225,7 @@ func (c *Conn) GetSessionUser(sessionPath dbus.ObjectPath) (*User, error) {
224225
// GetSessionDisplay may be used to get the display for specific session
225226
func (c *Conn) GetSessionDisplay(sessionPath dbus.ObjectPath) (string, error) {
226227
if len(sessionPath) == 0 {
227-
return "", fmt.Errorf("empty sessionPath")
228+
return "", errors.New("empty sessionPath")
228229
}
229230
sessionObj := c.conn.Object(dbusDest, sessionPath)
230231
display, err := sessionObj.GetProperty(dbusDest + ".Session.Display")

sdjournal/journal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ func (j *Journal) GetEntry() (*JournalEntry, error) {
796796
msg := C.GoStringN((*C.char)(d), C.int(l))
797797
kv := strings.SplitN(msg, "=", 2)
798798
if len(kv) < 2 {
799-
return nil, fmt.Errorf("failed to parse field")
799+
return nil, errors.New("failed to parse field")
800800
}
801801

802802
entry.Fields[kv[0]] = kv[1]
@@ -1102,7 +1102,7 @@ func (j *Journal) GetUniqueValues(field string) ([]string, error) {
11021102
msg := C.GoStringN((*C.char)(d), C.int(l))
11031103
kv := strings.SplitN(msg, "=", 2)
11041104
if len(kv) < 2 {
1105-
return nil, fmt.Errorf("failed to parse field")
1105+
return nil, errors.New("failed to parse field")
11061106
}
11071107

11081108
result = append(result, kv[1])

sdjournal/read.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ process:
258258
func simpleMessageFormatter(entry *JournalEntry) (string, error) {
259259
msg, ok := entry.Fields["MESSAGE"]
260260
if !ok {
261-
return "", fmt.Errorf("no MESSAGE field present in journal entry")
261+
return "", errors.New("no MESSAGE field present in journal entry")
262262
}
263263

264264
usec := entry.RealtimeTimestamp

unit/deserialize.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ func deserializeAll(f io.Reader) ([]*UnitSection, []*UnitOption, error) {
9494

9595
// sanity check. "should not happen" as sectionKind is first in code flow.
9696
if len(sections) == 0 {
97-
return nil, nil, fmt.Errorf(
98-
"Unit file misparse: option before section")
97+
return nil, nil, errors.New("unit file misparse: option before section")
9998
}
10099

101100
// add to newest section entries.

util/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
package util
2020

2121
import (
22-
"fmt"
22+
"errors"
2323
"os"
2424
"strings"
2525
)
2626

27-
var ErrNoCGO = fmt.Errorf("go-systemd built with CGO disabled")
27+
var ErrNoCGO = errors.New("go-systemd built with CGO disabled")
2828

2929
// GetRunningSlice attempts to retrieve the name of the systemd slice in which
3030
// the current process is running.

0 commit comments

Comments
 (0)