summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2024-04-24 10:53:39 +0200
committerGitHub <noreply@github.com>2024-04-24 10:53:39 +0200
commitb2ff09ec0cb8e10dad405c1d586aa09c8f073c2b (patch)
tree8d08ed9ea507a8d542e8b14bb0fb9dcaee437d34
parent0a5e9b2d60ae434331045a6a2a99e7eae5f5aa6b (diff)
parentdd6bfa1680f900b9242de3533196079c20b363de (diff)
Use errors.New instead of fmt.Errorf with no parameters (#3523)
-rw-r--r--pkg/commands/oscommands/copy.go4
-rw-r--r--pkg/utils/history_buffer.go8
-rw-r--r--pkg/utils/rebase_todo.go5
-rw-r--r--pkg/utils/yaml_utils/yaml_utils.go4
4 files changed, 12 insertions, 9 deletions
diff --git a/pkg/commands/oscommands/copy.go b/pkg/commands/oscommands/copy.go
index aab460e47..c6d83e23b 100644
--- a/pkg/commands/oscommands/copy.go
+++ b/pkg/commands/oscommands/copy.go
@@ -1,7 +1,7 @@
package oscommands
import (
- "fmt"
+ "errors"
"io"
"os"
"path/filepath"
@@ -86,7 +86,7 @@ func CopyDir(src string, dst string) (err error) {
return err
}
if !si.IsDir() {
- return fmt.Errorf("source is not a directory")
+ return errors.New("source is not a directory")
}
_, err = os.Stat(dst)
diff --git a/pkg/utils/history_buffer.go b/pkg/utils/history_buffer.go
index 73c33cb82..670004d02 100644
--- a/pkg/utils/history_buffer.go
+++ b/pkg/utils/history_buffer.go
@@ -1,6 +1,8 @@
package utils
-import "fmt"
+import (
+ "errors"
+)
type HistoryBuffer[T any] struct {
maxSize int
@@ -24,10 +26,10 @@ func (self *HistoryBuffer[T]) Push(item T) {
func (self *HistoryBuffer[T]) PeekAt(index int) (T, error) {
var item T
if len(self.items) == 0 {
- return item, fmt.Errorf("Buffer is empty")
+ return item, errors.New("Buffer is empty")
}
if len(self.items) <= index || index < -1 {
- return item, fmt.Errorf("Index out of range")
+ return item, errors.New("Index out of range")
}
if index == -1 {
return item, nil
diff --git a/pkg/utils/rebase_todo.go b/pkg/utils/rebase_todo.go
index e678a8f4e..d93eb4ac8 100644
--- a/pkg/utils/rebase_todo.go
+++ b/pkg/utils/rebase_todo.go
@@ -2,6 +2,7 @@ package utils
import (
"bytes"
+ "errors"
"fmt"
"os"
"slices"
@@ -48,7 +49,7 @@ func EditRebaseTodo(filePath string, changes []TodoChange, commentChar byte) err
if matchCount < len(changes) {
// Should never get here
- return fmt.Errorf("Some todos not found in git-rebase-todo")
+ return errors.New("Some todos not found in git-rebase-todo")
}
return WriteRebaseTodoFile(filePath, todos, commentChar)
@@ -197,7 +198,7 @@ func moveTodoUp(todos []todo.Todo, todoToMove Todo) ([]todo.Todo, error) {
if !ok {
// We expect callers to guard against this
- return []todo.Todo{}, fmt.Errorf("Destination position for moving todo is out of range")
+ return []todo.Todo{}, errors.New("Destination position for moving todo is out of range")
}
destinationIdx := sourceIdx + 1 + skip
diff --git a/pkg/utils/yaml_utils/yaml_utils.go b/pkg/utils/yaml_utils/yaml_utils.go
index 48f70fff0..37d521c6a 100644
--- a/pkg/utils/yaml_utils/yaml_utils.go
+++ b/pkg/utils/yaml_utils/yaml_utils.go
@@ -190,7 +190,7 @@ func walk(node *yaml.Node, path string, callback func(*yaml.Node, string) bool)
didChange := callback(node, path)
switch node.Kind {
case yaml.DocumentNode:
- return false, fmt.Errorf("Unexpected document node in the middle of a yaml tree")
+ return false, errors.New("Unexpected document node in the middle of a yaml tree")
case yaml.MappingNode:
for i := 0; i < len(node.Content); i += 2 {
name := node.Content[i].Value
@@ -219,7 +219,7 @@ func walk(node *yaml.Node, path string, callback func(*yaml.Node, string) bool)
case yaml.ScalarNode:
// nothing to do
case yaml.AliasNode:
- return false, fmt.Errorf("Alias nodes are not supported")
+ return false, errors.New("Alias nodes are not supported")
}
return didChange, nil