@@ -143,18 +143,28 @@ func FilterByCreatedAt(ctx context.Context, client *containerd.Client, before []
143
143
maxTime = time .Now ()
144
144
)
145
145
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
+
146
154
imageStore := client .ImageService ()
147
155
if len (before ) > 0 {
148
156
beforeImages , err := imageStore .List (ctx , before ... )
149
157
if err != nil {
150
158
return []images.Image {}, err
151
159
}
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
158
168
}
159
169
}
160
170
}
@@ -164,12 +174,14 @@ func FilterByCreatedAt(ctx context.Context, client *containerd.Client, before []
164
174
if err != nil {
165
175
return []images.Image {}, err
166
176
}
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
173
185
}
174
186
}
175
187
}
0 commit comments