Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-17 11:36:27 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-23 09:13:31 +0300
commitd270a521ec5e39f336bd269def7aaf74d9f9ce9c (patch)
tree6585ec23836b8d8abc22bf463c3e671ead28d882
parent584b529003efe914d497720620e387b17be146aa (diff)
command: Improve error messages to be Git-agnostic
The command package is not only used to spawn Git commands, but may also spawn any other arbitrary command. It's thus quite misleading that some of the error messages are mentioninng "GitCommand"s as context. Reword these errors to be command-agnostic. While at it, let's also use the `%w` formatter to chain errors together.
-rw-r--r--internal/command/command.go11
-rw-r--r--internal/command/command_test.go2
2 files changed, 8 insertions, 5 deletions
diff --git a/internal/command/command.go b/internal/command/command.go
index 61d7fb6ef..abf008f3d 100644
--- a/internal/command/command.go
+++ b/internal/command/command.go
@@ -214,8 +214,9 @@ func New(ctx context.Context, cmd *exec.Cmd, opts ...Option) (*Command, error) {
if _, ok := cfg.stdin.(stdinSentinel); ok {
pipe, err := cmd.StdinPipe()
if err != nil {
- return nil, fmt.Errorf("GitCommand: stdin: %v", err)
+ return nil, fmt.Errorf("creating stdin pipe: %w", err)
}
+
command.writer = pipe
} else if cfg.stdin != nil {
cmd.Stdin = cfg.stdin
@@ -228,8 +229,9 @@ func New(ctx context.Context, cmd *exec.Cmd, opts ...Option) (*Command, error) {
} else {
pipe, err := cmd.StdoutPipe()
if err != nil {
- return nil, fmt.Errorf("GitCommand: stdout: %v", err)
+ return nil, fmt.Errorf("creating stdout pipe: %w", err)
}
+
command.reader = pipe
}
@@ -238,13 +240,14 @@ func New(ctx context.Context, cmd *exec.Cmd, opts ...Option) (*Command, error) {
} else {
command.stderrBuffer, err = newStderrBuffer(maxStderrBytes, maxStderrLineLength, []byte("\n"))
if err != nil {
- return nil, fmt.Errorf("GitCommand: failed to create stderr buffer: %v", err)
+ return nil, fmt.Errorf("creating stderr buffer: %w", err)
}
+
cmd.Stderr = command.stderrBuffer
}
if err := cmd.Start(); err != nil {
- return nil, fmt.Errorf("GitCommand: start %v: %v", cmd.Args, err)
+ return nil, fmt.Errorf("starting process %v: %w", cmd.Args, err)
}
inFlightCommandGauge.Inc()
diff --git a/internal/command/command_test.go b/internal/command/command_test.go
index 5ac1aed85..1f6eae3b0 100644
--- a/internal/command/command_test.go
+++ b/internal/command/command_test.go
@@ -254,7 +254,7 @@ func TestNew_missingBinary(t *testing.T) {
ctx := testhelper.Context(t)
cmd, err := New(ctx, exec.Command("command-non-existent"))
- require.Equal(t, fmt.Errorf("GitCommand: start [command-non-existent]: exec: \"command-non-existent\": executable file not found in $PATH"), err)
+ require.EqualError(t, err, "starting process [command-non-existent]: exec: \"command-non-existent\": executable file not found in $PATH")
require.Nil(t, cmd)
}