~axwalk/juju-core/lp1303195-manual-ubuntuuser-bash

« back to all changes in this revision

Viewing changes to cmd/cmd.go

[r=klyachin],[bug=1227074] cmd: No longer panic if cwd is deleted

This adds error return value for cmd.DefaultContext() function:

func DefaultContext() (*Context, error)

The previous implemenation causes panic if cmd.DefaultContext() was called with deleted current directory.

https://codereview.appspot.com/78660045/

R=dimitern, klyachin

Show diffs side-by-side

added added

removed removed

Lines of Context:
224
224
}
225
225
 
226
226
// DefaultContext returns a Context suitable for use in non-hosted situations.
227
 
func DefaultContext() *Context {
 
227
func DefaultContext() (*Context, error) {
228
228
        dir, err := os.Getwd()
229
229
        if err != nil {
230
 
                panic(err)
 
230
                return nil, err
231
231
        }
232
232
        abs, err := filepath.Abs(dir)
233
233
        if err != nil {
234
 
                panic(err)
 
234
                return nil, err
235
235
        }
236
236
        return &Context{
237
237
                Dir:    abs,
238
238
                Stdin:  os.Stdin,
239
239
                Stdout: os.Stdout,
240
240
                Stderr: os.Stderr,
241
 
        }
 
241
        }, nil
242
242
}
243
243
 
244
244
// CheckEmpty is a utility function that returns an error if args is not empty.