Skip to content

Commit

Permalink
debos: Improve error messages
Browse files Browse the repository at this point in the history
Rework the error handling to show where an error occured during the run.
Also print all error messages to the log rather than stdout.

Signed-off-by: Christopher Obbard <[email protected]>
  • Loading branch information
obbardc authored and sjoerdsimons committed Jul 24, 2023
1 parent 0d1cab2 commit a25cb9a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cmd/debos/debos.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func main() {
// attempt to create a fakemachine
m, err = fakemachine.NewMachineWithBackend(options.Backend)
if err != nil {
log.Printf("error creating fakemachine: %v", err)
log.Printf("Couldn't create fakemachine: %w", err)

/* fallback to running on the host unless the user has chosen
* a specific backend */
Expand Down Expand Up @@ -253,7 +253,7 @@ func main() {
}
memsize, err := units.RAMInBytes(options.Memory)
if err != nil {
fmt.Printf("Couldn't parse memory size: %v\n", err)
log.Printf("Couldn't parse memory size: %w\n", err)
context.State = debos.Failed
return
}
Expand All @@ -268,7 +268,7 @@ func main() {
if options.ScratchSize != "" {
size, err := units.FromHumanSize(options.ScratchSize)
if err != nil {
fmt.Printf("Couldn't parse scratch size: %v\n", err)
log.Printf("Couldn't parse scratch size: %w\n", err)
context.State = debos.Failed
return
}
Expand Down Expand Up @@ -318,11 +318,12 @@ func main() {

exitcode, err := m.RunInMachineWithArgs(args)
if err != nil {
fmt.Println(err)
log.Printf("Couldn't start fakemachine: %w\n", err)
context.State = debos.Failed
return
}
if exitcode != 0 {
log.Printf("fakemachine failed with non-zero exitcode: %d\n", exitcode)
context.State = debos.Failed
return
}
Expand Down Expand Up @@ -354,6 +355,7 @@ func main() {
if _, err = os.Stat(context.Rootdir); os.IsNotExist(err) {
err = os.Mkdir(context.Rootdir, 0755)
if err != nil && os.IsNotExist(err) {
log.Printf("Couldn't create rootdir: %w\n", err)
context.State = debos.Failed
return
}
Expand Down

0 comments on commit a25cb9a

Please sign in to comment.