From e400e1757df4fe45a05b1b7b3dc20818f1a3350f Mon Sep 17 00:00:00 2001 From: Stanislav Chzhen Date: Thu, 21 Aug 2025 22:37:22 +0300 Subject: [PATCH] all: imp docs --- internal/agh/agh.go | 4 ++++ internal/aghos/os.go | 13 +++++++++---- internal/arpdb/arpdb.go | 2 +- internal/client/storage_test.go | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/internal/agh/agh.go b/internal/agh/agh.go index e3c42b94..c1cec8f3 100644 --- a/internal/agh/agh.go +++ b/internal/agh/agh.go @@ -67,6 +67,10 @@ type ExternalCommand struct { // keyCommand builds a key for a command lookup. func keyCommand(path string, args []string) (k string) { + if len(args) == 0 { + return path + } + return path + " " + strings.Join(args, " ") } diff --git a/internal/aghos/os.go b/internal/aghos/os.go index 086894fb..0c0460b4 100644 --- a/internal/aghos/os.go +++ b/internal/aghos/os.go @@ -114,7 +114,7 @@ func PIDByCommand( l.DebugContext(ctx, "executing", "cmd", psCmd, "args", psArgs) stdoutBuf := bytes.Buffer{} - err = executil.Run( + runErr := executil.Run( ctx, executil.SystemCommandConstructor{}, &executil.CommandConfig{ @@ -123,9 +123,6 @@ func PIDByCommand( Stdout: &stdoutBuf, }, ) - if err != nil { - return 0, fmt.Errorf("executing the command: %w", err) - } var instNum int pid, instNum, err = parsePSOutput(&stdoutBuf, command, except) @@ -143,6 +140,14 @@ func PIDByCommand( l.WarnContext(ctx, "instances found", "num", instNum, "command", command) } + if runErr != nil { + if code, ok := executil.ExitCodeFromError(runErr); ok { + return 0, fmt.Errorf("ps finished with code %d", code) + } + + return 0, fmt.Errorf("executing the command: %w", runErr) + } + return pid, nil } diff --git a/internal/arpdb/arpdb.go b/internal/arpdb/arpdb.go index 7f6c1a1c..a2a08238 100644 --- a/internal/arpdb/arpdb.go +++ b/internal/arpdb/arpdb.go @@ -32,7 +32,7 @@ type Interface interface { // Refresher updates the stored data. It must be safe for concurrent use. service.Refresher - // Neighbors returnes the last set of data reported by ARP. Both the method + // Neighbors returns the last set of data reported by ARP. Both the method // and it's result must be safe for concurrent use. Neighbors() (ns []Neighbor) } diff --git a/internal/client/storage_test.go b/internal/client/storage_test.go index 32f34c00..38bc4f56 100644 --- a/internal/client/storage_test.go +++ b/internal/client/storage_test.go @@ -68,7 +68,7 @@ type Interface interface { // Refresher updates the stored data. It must be safe for concurrent use. service.Refresher - // Neighbors returnes the last set of data reported by ARP. Both the method + // Neighbors returns the last set of data reported by ARP. Both the method // and it's result must be safe for concurrent use. Neighbors() (ns []arpdb.Neighbor) }