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

« back to all changes in this revision

Viewing changes to cmd/plugins/juju-metadata/metadata.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:
25
25
// to the cmd package. This function is not redundant with main, because it
26
26
// provides an entry point for testing with arbitrary command line arguments.
27
27
func Main(args []string) {
 
28
        ctx, err := cmd.DefaultContext()
 
29
        if err != nil {
 
30
                fmt.Fprintf(os.Stderr, "error: %v\n", err)
 
31
                os.Exit(2)
 
32
        }
28
33
        if err := juju.InitJujuHome(); err != nil {
29
34
                fmt.Fprintf(os.Stderr, "error: %s\n", err)
30
35
                os.Exit(2)
42
47
        metadatacmd.Register(&ValidateToolsMetadataCommand{})
43
48
        metadatacmd.Register(&SignMetadataCommand{})
44
49
 
45
 
        os.Exit(cmd.Main(metadatacmd, cmd.DefaultContext(), args[1:]))
 
50
        os.Exit(cmd.Main(metadatacmd, ctx, args[1:]))
46
51
}
47
52
 
48
53
func main() {