mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(agent/agentcontainers): remove empty warning if no containers exist (#16748)
Fixes the current annoying response if no containers are running:
```
{"containers":null,"warnings":[""]}
```
This commit is contained in:
@@ -253,11 +253,16 @@ func (dcl *DockerCLILister) List(ctx context.Context) (codersdk.WorkspaceAgentLi
|
||||
return codersdk.WorkspaceAgentListContainersResponse{}, xerrors.Errorf("scan docker ps output: %w", err)
|
||||
}
|
||||
|
||||
res := codersdk.WorkspaceAgentListContainersResponse{
|
||||
Containers: make([]codersdk.WorkspaceAgentDevcontainer, 0, len(ids)),
|
||||
Warnings: make([]string, 0),
|
||||
}
|
||||
dockerPsStderr := strings.TrimSpace(stderrBuf.String())
|
||||
if dockerPsStderr != "" {
|
||||
res.Warnings = append(res.Warnings, dockerPsStderr)
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return codersdk.WorkspaceAgentListContainersResponse{
|
||||
Warnings: []string{dockerPsStderr},
|
||||
}, nil
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// now we can get the detailed information for each container
|
||||
@@ -273,13 +278,10 @@ func (dcl *DockerCLILister) List(ctx context.Context) (codersdk.WorkspaceAgentLi
|
||||
return codersdk.WorkspaceAgentListContainersResponse{}, xerrors.Errorf("run docker inspect: %w", err)
|
||||
}
|
||||
|
||||
res := codersdk.WorkspaceAgentListContainersResponse{
|
||||
Containers: make([]codersdk.WorkspaceAgentDevcontainer, len(ins)),
|
||||
}
|
||||
for idx, in := range ins {
|
||||
for _, in := range ins {
|
||||
out, warns := convertDockerInspect(in)
|
||||
res.Warnings = append(res.Warnings, warns...)
|
||||
res.Containers[idx] = out
|
||||
res.Containers = append(res.Containers, out)
|
||||
}
|
||||
|
||||
if dockerPsStderr != "" {
|
||||
|
||||
Reference in New Issue
Block a user