@@ -145,18 +145,28 @@ func FilterByCreatedAt(ctx context.Context, client *containerd.Client, before []
145
145
maxTime = time .Now ()
146
146
)
147
147
148
+ fetchImageNames := func (names []string ) string {
149
+ parsedNames := make ([]string , 0 , len (names ))
150
+ for _ , name := range names {
151
+ parsedNames = append (parsedNames , strings .TrimPrefix (name , "name==" ))
152
+ }
153
+ return strings .Join (parsedNames , "," )
154
+ }
155
+
148
156
imageStore := client .ImageService ()
149
157
if len (before ) > 0 {
150
158
beforeImages , err := imageStore .List (ctx , before ... )
151
159
if err != nil {
152
160
return []images.Image {}, err
153
161
}
154
- if len (beforeImages ) > 0 {
155
- maxTime = beforeImages [0 ].CreatedAt
156
- for _ , image := range beforeImages {
157
- if image .CreatedAt .After (maxTime ) {
158
- maxTime = image .CreatedAt
159
- }
162
+ if len (beforeImages ) == 0 {
163
+ //nolint:stylecheck
164
+ return []images.Image {}, fmt .Errorf ("No such image: %s" , fetchImageNames (before ))
165
+ }
166
+ maxTime = beforeImages [0 ].CreatedAt
167
+ for _ , image := range beforeImages {
168
+ if image .CreatedAt .After (maxTime ) {
169
+ maxTime = image .CreatedAt
160
170
}
161
171
}
162
172
}
@@ -166,12 +176,14 @@ func FilterByCreatedAt(ctx context.Context, client *containerd.Client, before []
166
176
if err != nil {
167
177
return []images.Image {}, err
168
178
}
169
- if len (sinceImages ) > 0 {
170
- minTime = sinceImages [0 ].CreatedAt
171
- for _ , image := range sinceImages {
172
- if image .CreatedAt .Before (minTime ) {
173
- minTime = image .CreatedAt
174
- }
179
+ if len (sinceImages ) == 0 {
180
+ //nolint:stylecheck
181
+ return []images.Image {}, fmt .Errorf ("No such image: %s" , fetchImageNames (since ))
182
+ }
183
+ minTime = sinceImages [0 ].CreatedAt
184
+ for _ , image := range sinceImages {
185
+ if image .CreatedAt .Before (minTime ) {
186
+ minTime = image .CreatedAt
175
187
}
176
188
}
177
189
}
0 commit comments