@@ -153,16 +153,23 @@ func (c *Client) Download(ctx context.Context, dst string, opt types.RegistryOpt
153
153
log .Debug ("No metadata file" )
154
154
}
155
155
156
- art , err := c .initOCIArtifact (opt )
157
- if err != nil {
158
- return xerrors .Errorf ("OCI artifact error: %w" , err )
159
- }
160
-
161
- if err = art .Download (ctx , dst , oci.DownloadOption {MediaType : dbMediaType }); err != nil {
156
+ art := c .initOCIArtifact (opt )
157
+ if err := art .Download (ctx , dst , oci.DownloadOption {MediaType : dbMediaType }); err != nil {
158
+ var terr * transport.Error
159
+ if errors .As (err , & terr ) {
160
+ for _ , diagnostic := range terr .Errors {
161
+ // For better user experience
162
+ if diagnostic .Code == transport .DeniedErrorCode || diagnostic .Code == transport .UnauthorizedErrorCode {
163
+ // e.g. https://aquasecurity.github.io/trivy/latest/docs/references/troubleshooting/#db
164
+ log .Warnf ("See %s" , doc .URL ("/docs/references/troubleshooting/" , "db" ))
165
+ break
166
+ }
167
+ }
168
+ }
162
169
return xerrors .Errorf ("database download error: %w" , err )
163
170
}
164
171
165
- if err = c .updateDownloadedAt (ctx , dst ); err != nil {
172
+ if err : = c .updateDownloadedAt (ctx , dst ); err != nil {
166
173
return xerrors .Errorf ("failed to update downloaded_at: %w" , err )
167
174
}
168
175
return nil
@@ -194,27 +201,11 @@ func (c *Client) updateDownloadedAt(ctx context.Context, dbDir string) error {
194
201
return nil
195
202
}
196
203
197
- func (c * Client ) initOCIArtifact (opt types.RegistryOptions ) ( * oci.Artifact , error ) {
204
+ func (c * Client ) initOCIArtifact (opt types.RegistryOptions ) * oci.Artifact {
198
205
if c .artifact != nil {
199
- return c .artifact , nil
200
- }
201
-
202
- art , err := oci .NewArtifact (c .dbRepository .String (), c .quiet , opt )
203
- if err != nil {
204
- var terr * transport.Error
205
- if errors .As (err , & terr ) {
206
- for _ , diagnostic := range terr .Errors {
207
- // For better user experience
208
- if diagnostic .Code == transport .DeniedErrorCode || diagnostic .Code == transport .UnauthorizedErrorCode {
209
- // e.g. https://aquasecurity.github.io/trivy/latest/docs/references/troubleshooting/#db
210
- log .Warnf ("See %s" , doc .URL ("/docs/references/troubleshooting/" , "db" ))
211
- break
212
- }
213
- }
214
- }
215
- return nil , xerrors .Errorf ("OCI artifact error: %w" , err )
206
+ return c .artifact
216
207
}
217
- return art , nil
208
+ return oci . NewArtifact ( c . dbRepository . String (), c . quiet , opt )
218
209
}
219
210
220
211
func (c * Client ) ShowInfo () error {
0 commit comments