Merge lp:~sergiusens/goget-ubuntu-touch/ErrExec into lp:goget-ubuntu-touch

Proposed by Sergio Schvezov on 2015-07-10
Status: Merged
Approved by: John Lenton on 2015-07-10
Approved revision: 202
Merged at revision: 202
Proposed branch: lp:~sergiusens/goget-ubuntu-touch/ErrExec
Merge into: lp:goget-ubuntu-touch
Diff against target: 80 lines (+26/-10)
2 files modified
diskimage/common.go (+12/-9)
diskimage/errors.go (+14/-1)
To merge this branch: bzr merge lp:~sergiusens/goget-ubuntu-touch/ErrExec
Reviewer Review Type Date Requested Status
John Lenton 2015-07-10 Approve on 2015-07-10
Review via email: mp+264440@code.launchpad.net

Commit Message

Better errors when executing commands in diskimage

To post a comment you must log in.
John Lenton (chipaca) wrote :

I wonder how many times we're going to recreate this pattern before we make it part of our toolset.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'diskimage/common.go'
2--- diskimage/common.go 2015-07-09 10:00:18 +0000
3+++ diskimage/common.go 2015-07-10 17:13:52 +0000
4@@ -343,13 +343,15 @@
5 }
6
7 for _, part := range img.parts {
8- if err := exec.Command("dmsetup", "clear", part.loop).Run(); err != nil {
9- return err
10+ dmsetupCmd := []string{"dmsetup", "clear", part.loop}
11+ if out, err := exec.Command(dmsetupCmd[0], dmsetupCmd[1:]...).CombinedOutput(); err != nil {
12+ return &ErrExec{command: dmsetupCmd, output: out}
13 }
14 }
15
16- if err := exec.Command("kpartx", "-ds", img.location).Run(); err != nil {
17- return err
18+ kpartxCmd := []string{"kpartx", "-ds", img.location}
19+ if out, err := exec.Command(kpartxCmd[0], kpartxCmd[1:]...).CombinedOutput(); err != nil {
20+ return &ErrExec{command: kpartxCmd, output: out}
21 }
22
23 unmapPartitions(img.parts)
24@@ -377,7 +379,7 @@
25 dev := filepath.Join("/dev/mapper", part.loop)
26
27 if part.fs == fsFat32 {
28- cmd := []string{"-F", "32", "-n", string(part.label)}
29+ cmd := []string{"mkfs.vfat", "-F", "32", "-n", string(part.label)}
30
31 size, err := sectorSize(dev)
32 if err != nil {
33@@ -390,12 +392,13 @@
34
35 cmd = append(cmd, "-S", size, dev)
36
37- if out, err := exec.Command("mkfs.vfat", cmd...).CombinedOutput(); err != nil {
38- return fmt.Errorf("unable to create filesystem: %s", out)
39+ if out, err := exec.Command(cmd[0], cmd[1:]...).CombinedOutput(); err != nil {
40+ return &ErrExec{command: cmd, output: out}
41 }
42 } else {
43- if out, err := exec.Command("mkfs.ext4", "-F", "-L", string(part.label), dev).CombinedOutput(); err != nil {
44- return fmt.Errorf("unable to create filesystem: %s", out)
45+ cmd := []string{"mkfs.ext4", "-F", "-L", string(part.label), dev}
46+ if out, err := exec.Command(cmd[0], cmd[1:]...).CombinedOutput(); err != nil {
47+ return &ErrExec{command: cmd, output: out}
48 }
49 }
50 }
51
52=== modified file 'diskimage/errors.go'
53--- diskimage/errors.go 2015-06-15 15:15:39 +0000
54+++ diskimage/errors.go 2015-07-10 17:13:52 +0000
55@@ -7,7 +7,10 @@
56 //
57 package diskimage
58
59-import "fmt"
60+import (
61+ "fmt"
62+ "strings"
63+)
64
65 // ErrMount represents a mount error
66 type ErrMount struct {
67@@ -30,3 +33,13 @@
68 func (e ErrMapCount) Error() string {
69 return fmt.Sprintf("expected %d partitons but found %d", e.expectedParts, e.foundParts)
70 }
71+
72+// ErrExec is an error from an external command
73+type ErrExec struct {
74+ output []byte
75+ command []string
76+}
77+
78+func (e ErrExec) Error() string {
79+ return fmt.Sprintf("error while executing external command %s: %s", strings.Join(e.command, " "), e.output)
80+}

Subscribers

People subscribed via source and target branches