X Tutup
Skip to content

Commit 5b2c52c

Browse files
committed
Fix docker-archive-public#2888 - Multi-line errors in ls mess with tab writing
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
1 parent c341a28 commit 5b2c52c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

commands/ls.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,18 +468,22 @@ func getHostListItems(hostList []*host.Host, hostsInError map[string]error) []Ho
468468
close(hostListItemsChan)
469469

470470
for name, err := range hostsInError {
471-
itemInError := HostListItem{}
472-
itemInError.Name = name
473-
itemInError.DriverName = "not found"
474-
itemInError.State = state.Error
475-
itemInError.Error = err.Error()
476-
hostListItems = append(hostListItems, itemInError)
471+
hostListItems = append(hostListItems, newHostListItemInError(name, err))
477472
}
478473

479474
sortHostListItemsByName(hostListItems)
480475
return hostListItems
481476
}
482477

478+
func newHostListItemInError(name string, err error) HostListItem {
479+
return HostListItem{
480+
Name: name,
481+
DriverName: "not found",
482+
State: state.Error,
483+
Error: strings.Replace(err.Error(), "\n", " ", -1),
484+
}
485+
}
486+
483487
func sortHostListItemsByName(items []HostListItem) {
484488
m := make(map[string]HostListItem, len(items))
485489
s := make([]string, len(items))

commands/ls_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,3 +528,11 @@ func TestGetSomeHostInError(t *testing.T) {
528528
assert.Equal(t, "foo", hostItem.Name)
529529
assert.Equal(t, state.Running, hostItem.State)
530530
}
531+
532+
func TestOnErrorWithMultilineComment(t *testing.T) {
533+
err := errors.New("MissingParameter: The request must contain the parameter InstanceId\n status code: 400, request id:")
534+
535+
itemInError := newHostListItemInError("foo", err)
536+
537+
assert.Equal(t, itemInError.Error, "MissingParameter: The request must contain the parameter InstanceId status code: 400, request id:")
538+
}

0 commit comments

Comments
 (0)
X Tutup