@@ -143,18 +143,28 @@ func FilterByCreatedAt(ctx context.Context, client *containerd.Client, before []
143143 maxTime = time .Now ()
144144 )
145145
146+ fetchImageNames := func (names []string ) string {
147+ parsedNames := make ([]string , 0 , len (names ))
148+ for _ , name := range names {
149+ parsedNames = append (parsedNames , strings .TrimPrefix (name , "name==" ))
150+ }
151+ return strings .Join (parsedNames , "," )
152+ }
153+
146154 imageStore := client .ImageService ()
147155 if len (before ) > 0 {
148156 beforeImages , err := imageStore .List (ctx , before ... )
149157 if err != nil {
150158 return []images.Image {}, err
151159 }
152- if len (beforeImages ) > 0 {
153- maxTime = beforeImages [0 ].CreatedAt
154- for _ , image := range beforeImages {
155- if image .CreatedAt .After (maxTime ) {
156- maxTime = image .CreatedAt
157- }
160+ if len (beforeImages ) == 0 {
161+ //nolint:stylecheck
162+ return []images.Image {}, fmt .Errorf ("No such image: %s" , fetchImageNames (before ))
163+ }
164+ maxTime = beforeImages [0 ].CreatedAt
165+ for _ , image := range beforeImages {
166+ if image .CreatedAt .After (maxTime ) {
167+ maxTime = image .CreatedAt
158168 }
159169 }
160170 }
@@ -164,12 +174,14 @@ func FilterByCreatedAt(ctx context.Context, client *containerd.Client, before []
164174 if err != nil {
165175 return []images.Image {}, err
166176 }
167- if len (sinceImages ) > 0 {
168- minTime = sinceImages [0 ].CreatedAt
169- for _ , image := range sinceImages {
170- if image .CreatedAt .Before (minTime ) {
171- minTime = image .CreatedAt
172- }
177+ if len (sinceImages ) == 0 {
178+ //nolint:stylecheck
179+ return []images.Image {}, fmt .Errorf ("No such image: %s" , fetchImageNames (since ))
180+ }
181+ minTime = sinceImages [0 ].CreatedAt
182+ for _ , image := range sinceImages {
183+ if image .CreatedAt .Before (minTime ) {
184+ minTime = image .CreatedAt
173185 }
174186 }
175187 }
0 commit comments