Skip to content

Commit

Permalink
commands: Rework newQemuHelper to bubble-up error instead of panicing
Browse files Browse the repository at this point in the history
Rather than panicing on error, bubble up an error so that the execution
may recover correctly and the error shown to the user.

Fixes: #413
Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
  • Loading branch information
obbardc committed Jul 26, 2023
1 parent 1ea5f88 commit 20281cc
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ func (cmd *Command) restoreResolvConf(sum *[sha256.Size]byte) error {
}

func (cmd Command) Run(label string, cmdline ...string) error {
q := newQemuHelper(cmd)
q, err := newQemuHelper(cmd)
if err != nil {
return err
}

q.Setup()
defer q.Cleanup()

Expand Down Expand Up @@ -283,11 +287,11 @@ type qemuHelper struct {
qemutarget string
}

func newQemuHelper(c Command) qemuHelper {
func newQemuHelper(c Command) (*qemuHelper, error) {
q := qemuHelper{}

if c.Chroot == "" || c.Architecture == "" {
return q
return &q, nil
}

switch c.Architecture {
Expand All @@ -306,14 +310,14 @@ func newQemuHelper(c Command) qemuHelper {
case "amd64", "i386":
/* Dummy, no qemu */
default:
log.Panicf("Don't know qemu for Architecture %s", c.Architecture)
return nil, fmt.Errorf("Don't know qemu for architecture %s", c.Architecture)
}

if q.qemusrc != "" {
q.qemutarget = path.Join(c.Chroot, q.qemusrc)
}

return q
return &q, nil
}

func (q qemuHelper) Setup() error {
Expand Down

0 comments on commit 20281cc

Please sign in to comment.