-
Notifications
You must be signed in to change notification settings - Fork 24
Surface Incus stderr in error messages from IncusOutput wrapper #276
Copy link
Copy link
Open
Description
Problem
container.IncusOutput() captures stdout but discards stderr. When the underlying incus command fails, callers only see exit status N instead of the actual error message from Incus. This makes debugging coi container info, coi container list, coi image info, etc. harder than necessary.
Example:
```
$ coi container info nonexistent
Error: failed to get container info: exit status 1
```
Expected:
```
$ coi container info nonexistent
Error: failed to get container info: exit status 1: Error: Instance not found
```
Context
Raised by Copilot during PR #274 review on the new container info / image info commands. Not addressed in that PR because:
- The suggested
IncusOutputWithStderrhelper does not exist in the codebase - Fixing only the two new commands would introduce inconsistency —
container list,image list, and other callers have the same problem - A uniform fix requires adding a new helper and migrating all call sites, which is out of scope for a CLI consistency PR
Proposed approach
- Add a new helper in `internal/container/` (e.g. `IncusOutputWithStderr`) that captures both stdout and stderr from `incus` commands
- On error, include the trimmed stderr in the returned error so callers can wrap it with context
- Migrate all `IncusOutput` call sites to the new helper — or change `IncusOutput` itself if no callers rely on the current stderr-silencing behavior
- Callers should format errors like:
```go
if err != nil {
if stderr := strings.TrimSpace(stderrOutput); stderr != "" {
return fmt.Errorf("failed to X: %v: %s", err, stderr)
}
return fmt.Errorf("failed to X: %v", err)
}
```
Affected call sites
At minimum:
- `internal/cli/container.go` — `container info`, `container list`
- `internal/cli/images.go` — `image info`
- Any other callers of `container.IncusOutput` in the codebase
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels