From 2810962586e0340998466bd6a4804dce51b2ff33 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Wed, 9 Mar 2022 11:25:38 +0000 Subject: [PATCH] debos: Improve error messages 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 --- cmd/debos/debos.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/debos/debos.go b/cmd/debos/debos.go index 6060e3ca..36f14a52 100644 --- a/cmd/debos/debos.go +++ b/cmd/debos/debos.go @@ -162,7 +162,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: %v", err) /* fallback to running on the host unless the user has chosen * a specific backend */ @@ -252,7 +252,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: %v\n", err) context.State = debos.Failed return } @@ -267,7 +267,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: %v\n", err) context.State = debos.Failed return } @@ -317,12 +317,13 @@ func main() { exitcode, err := m.RunInMachineWithArgs(args) if err != nil { - fmt.Println(err) + log.Printf("Couldn't start fakemachine: %v\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 } @@ -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: %v\n", err) context.State = debos.Failed return }