Skip to content

Commit

Permalink
Use errors.New instead of fmt.Errorf with no parameters (#3523)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhaller committed Apr 24, 2024
2 parents 0a5e9b2 + dd6bfa1 commit b2ff09e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/commands/oscommands/copy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package oscommands

import (
"fmt"
"errors"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions pkg/utils/history_buffer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package utils

import "fmt"
import (
"errors"
)

type HistoryBuffer[T any] struct {
maxSize int
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkg/utils/rebase_todo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"bytes"
"errors"
"fmt"
"os"
"slices"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/yaml_utils/yaml_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b2ff09e

Please sign in to comment.