Mercurial > hg > Members > anatofuz > growsync
changeset 8:c775cee5aac2
fix error
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 07 Dec 2020 10:10:16 +0900 |
parents | 6da31576fa84 |
children | 11ceb718f9f6 |
files | cmd_edit.go cmd_push.go config.go editor.go |
diffstat | 4 files changed, 21 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/cmd_edit.go Mon Dec 07 08:38:09 2020 +0900 +++ b/cmd_edit.go Mon Dec 07 10:10:16 2020 +0900 @@ -8,6 +8,8 @@ "os" "path/filepath" "time" + + "golang.org/x/xerrors" ) type editCmd struct{} @@ -27,7 +29,7 @@ fs.SetOutput(errorWriter) if err := fs.Parse(argv); err != nil { - return nil + return xerrors.Errorf("[error] failed parse argv %+w", err) } var growiPATH string @@ -47,25 +49,25 @@ if alreadyExistsFile { info, err := os.Stat(localFilePATH) if err != nil { - return err + return xerrors.Errorf("[error] failed file stat %s %+w", localFilePATH, err) } beforeTime = info.ModTime() } client, err := NewGrowiClient(config.URL, config.TOKEN) if err != nil { - return err + return xerrors.Errorf("[error] failed growi client %+w", err) } err = doEdit(localFilePATH) if err != nil { - return fmt.Errorf("failed edit mardkwodn file %+v", err) + return xerrors.Errorf("failed edit mardkwodn file %+w", err) } if alreadyExistsFile { info, err := os.Stat(localFilePATH) if err != nil { - return err + return xerrors.Errorf("[error] failed file stat %s %+w", localFilePATH, err) } if info.ModTime() == beforeTime {
--- a/cmd_push.go Mon Dec 07 08:38:09 2020 +0900 +++ b/cmd_push.go Mon Dec 07 10:10:16 2020 +0900 @@ -23,7 +23,7 @@ fs.SetOutput(errorWriter) if err := fs.Parse(argv); err != nil { - return nil + return xerrors.Errorf("[error] failed parse argv %+w", err) } if fs.NArg() < 1 { @@ -32,7 +32,7 @@ client, err := NewGrowiClient(config.URL, config.TOKEN) if err != nil { - return err + return xerrors.Errorf("[error] failed growi client %+w", err) } markdownPATH := fs.Arg(0) @@ -40,7 +40,7 @@ id, err := client.IsExistsPageOnGrowi(growiSystemPath) if err != nil { - return err + return xerrors.Errorf("[error] failed get page %s %+w", growiSystemPath, err) } if id == nil {
--- a/config.go Mon Dec 07 08:38:09 2020 +0900 +++ b/config.go Mon Dec 07 10:10:16 2020 +0900 @@ -7,6 +7,7 @@ "path/filepath" "github.com/goccy/go-yaml" + "golang.org/x/xerrors" ) type growiConfig struct { @@ -21,12 +22,12 @@ configFilePATH, _ := getConfingPATH() configBytes, err := ioutil.ReadFile(configFilePATH) if err != nil { - return nil, err + return nil, xerrors.Errorf("failed read %s : %+w", configFilePATH, err) } config := growiConfig{} if err := yaml.Unmarshal(configBytes, &config); err != nil { - return nil, err + return nil, xerrors.Errorf("failed unmarshal yaml at %s, %+w", configFilePATH, err) } return &config, nil } @@ -34,7 +35,7 @@ func getConfingPATH() (string, error) { home, err := os.UserHomeDir() if err != nil { - return "", err + return "", xerrors.Errorf("[error] failed get user homedir %+w", err) } configFilePATH := filepath.Join(home, ".config", "growsync", "config.yaml") if !existsFile(configFilePATH) {
--- a/editor.go Mon Dec 07 08:38:09 2020 +0900 +++ b/editor.go Mon Dec 07 10:10:16 2020 +0900 @@ -6,6 +6,7 @@ "strings" "github.com/mattn/go-tty" + "golang.org/x/xerrors" ) func doEdit(mdfilePATH string) error { @@ -15,7 +16,7 @@ } tty, err := tty.Open() if err != nil { - return err + return xerrors.Errorf("[error] failed open tty %+w", err) } defer tty.Close() @@ -27,5 +28,9 @@ cmd.Stdout = tty.Output() cmd.Stderr = tty.Output() - return cmd.Run() + if err := cmd.Run(); err != nil { + return xerrors.Errorf("[error] failed exec editor %+w", err) + } + + return nil }