Fix panic condition on docker pull failure (#1968)

* [wip] add image pull error handlers

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* fix panic and ui hang on docker pull failure

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* linter fix

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

---------

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Alex Goodman 2023-07-27 11:32:02 -04:00 committed by GitHub
parent d84120f499
commit bbd2d42dbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -15,6 +15,7 @@ import (
"github.com/anchore/syft/internal/bus" "github.com/anchore/syft/internal/bus"
"github.com/anchore/syft/internal/config" "github.com/anchore/syft/internal/config"
"github.com/anchore/syft/internal/file" "github.com/anchore/syft/internal/file"
"github.com/anchore/syft/internal/log"
"github.com/anchore/syft/internal/version" "github.com/anchore/syft/internal/version"
"github.com/anchore/syft/syft" "github.com/anchore/syft/syft"
"github.com/anchore/syft/syft/artifact" "github.com/anchore/syft/syft/artifact"
@ -101,14 +102,19 @@ func execWorker(app *config.Application, userInput string, writer sbom.Writer) <
}, },
) )
if src != nil {
defer src.Close()
}
if err != nil { if err != nil {
errs <- fmt.Errorf("failed to construct source from user input %q: %w", userInput, err) errs <- fmt.Errorf("failed to construct source from user input %q: %w", userInput, err)
return return
} }
defer func() {
if src != nil {
if err := src.Close(); err != nil {
log.Tracef("unable to close source: %+v", err)
}
}
}()
s, err := GenerateSBOM(src, errs, app) s, err := GenerateSBOM(src, errs, app)
if err != nil { if err != nil {
errs <- err errs <- err

View File

@ -82,12 +82,15 @@ func (m *UI) Teardown(force bool) error {
if !force { if !force {
m.handler.Running.Wait() m.handler.Running.Wait()
m.program.Quit() m.program.Quit()
// typically in all cases we would want to wait for the UI to finish. However there are still error cases
// that are not accounted for, resulting in hangs. For now, we'll just wait for the UI to finish in the
// happy path only. There will always be an indication of the problem to the user via reporting the error
// string from the worker (outside of the UI after teardown).
m.running.Wait()
} else { } else {
m.program.Kill() m.program.Kill()
} }
m.running.Wait()
// TODO: allow for writing out the full log output to the screen (only a partial log is shown currently) // TODO: allow for writing out the full log output to the screen (only a partial log is shown currently)
// this needs coordination to know what the last frame event is to change the state accordingly (which isn't possible now) // this needs coordination to know what the last frame event is to change the state accordingly (which isn't possible now)