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-17 11:57:37 +0300
commit5767f0de28a784332e5001b35c7e47caee427d93 (patch)
tree1c563f722d4386253c5502066d8c59ee09c7c888
parent088b56f72d3ea3dc3d90a55c516002b8fd71541d (diff)
command: Improve error messages to be Git-agnosticpks-ssh-tests-emulate-client-side
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 e544d99ab..f5bc1d131 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)
}