From a88acb58d41eec81791e97672c5318f4582e00dc Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Tue, 17 Aug 2021 22:11:09 +0100 Subject: [PATCH] fix: Avoid crash when asking for no existing transition/expiry info (#3771) mc ilm ls has --expiry and --transition to show for only expiry or transition information, but if one of them doesn't exist, mc crashes. The PR fixes this. Co-authored-by: Anis Elleuch --- cmd/ilm-ls.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/ilm-ls.go b/cmd/ilm-ls.go index a437ea38..f5a689b5 100644 --- a/cmd/ilm-ls.go +++ b/cmd/ilm-ls.go @@ -116,8 +116,10 @@ func (i ilmListMessage) String() string { tbl = newPrettyTable(tableSeperator, fields...) tblContents = getILMHeader(&tbl, alignedHdrLabels...) - // Reuse the fields - fields = nil + // If no data to show at all, quit here + if len(cellDataNoTags) == 0 && len(cellDataWithTags) == 0 { + return tblContents + } // The data table var tblRowField *[]string @@ -127,6 +129,9 @@ func (i ilmListMessage) String() string { tblRowField = &cellDataNoTags[0] } + // Reuse the fields + fields = nil + for _, hdr := range *tblRowField { fields = append(fields, Field{ilmThemeRow, len(hdr)}) }