TBR: v.io/jiri/profiles: print cwd on error.
- print out the current working dir when an error is encountered
in a sequence Run/Last command.
Change-Id: I56d6305cb9e9dcb5a4b783ade3202d638373ea90
diff --git a/runutil/sequence.go b/runutil/sequence.go
index ab280bf..68c00b9 100644
--- a/runutil/sequence.go
+++ b/runutil/sequence.go
@@ -166,6 +166,9 @@
}
opts := s.GetOpts()
stdout := opts.Stdout
+ if stdout == nil {
+ return func() {}
+ }
opts.Stdout = f
opts.Stderr = f
s.setOpts(opts)
@@ -175,9 +178,11 @@
if opts.Verbose || s.err != nil {
// TODO(cnicolaou): probably best to stream this out rather
// than buffer the whole file into memory.
- data, err := ioutil.ReadFile(filename)
- if err == nil {
+ if data, err := ioutil.ReadFile(filename); err == nil {
fmt.Fprint(stdout, string(data))
+ if wd, err := os.Getwd(); err == nil {
+ fmt.Fprintf(stdout, "Current Directory: %v\n", wd)
+ }
}
}
os.Remove(filename)
diff --git a/runutil/sequence_test.go b/runutil/sequence_test.go
index d91294e..b44c3da 100644
--- a/runutil/sequence_test.go
+++ b/runutil/sequence_test.go
@@ -303,7 +303,7 @@
err = seq.Run("sh", "-c", "echo AA").
Run("sh", "-c", "echo BB; exit 1").
Last("sh", "-c", "echo CC")
- if got, want := strings.Count(out.String(), "\n"), 6; got != want {
+ if got, want := strings.Count(out.String(), "\n"), 8; got != want {
t.Errorf("got %v, want %v", got, want)
}
if got, want := strings.Count(out.String(), "AA"), 2; got != want {
@@ -360,7 +360,11 @@
if err != nil {
t.Fatal(err)
}
- if got, want := string(data), "aha\n"; got != want {
+ cwd, err := os.Getwd()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if got, want := string(data), "aha\nCurrent Directory: "+cwd+"\n"; got != want {
t.Errorf("got %v, want %v", got, want)
}
}