diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2021-02-22 22:03:29 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2021-02-22 23:05:49 -0700 |
commit | 89f98d13da60b4768f3f2e61594d027b009b920d (patch) | |
tree | 630f9feae81fdfc060e07729f4b153be0d4ce41e | |
parent | 88017a8d5ca3739cf0216848f53d1e653bf63aaa (diff) |
ez reader: Fix error handling
-rw-r--r-- | cmd_command.go | 10 | ||||
-rw-r--r-- | ez.go | 7 |
2 files changed, 8 insertions, 9 deletions
diff --git a/cmd_command.go b/cmd_command.go index 700e47d..32292d3 100644 --- a/cmd_command.go +++ b/cmd_command.go @@ -75,7 +75,7 @@ func (c CmdCommit) fiCmdWrite(fiw fiWriter) error { func init() { parser_registerCmd("commit ", CmdCommit{}) } func (CmdCommit) fiCmdRead(fir fiReader) (cmd Cmd, err error) { ez := &ezfir{fir: fir} - defer func() { err = ez.Defer() }() + defer ez.Defer(&err) // 'commit' SP <ref> LF c := CmdCommit{Ref: trimLinePrefix(ez.ReadLine(), "commit ")} @@ -176,7 +176,7 @@ func (c CmdTag) fiCmdWrite(fiw fiWriter) error { func init() { parser_registerCmd("tag ", CmdTag{}) } func (CmdTag) fiCmdRead(fir fiReader) (cmd Cmd, err error) { ez := &ezfir{fir: fir} - defer func() { err = ez.Defer() }() + defer ez.Defer(&err) // 'tag' SP <name> LF c := CmdTag{RefName: trimLinePrefix(ez.ReadLine(), "tag ")} @@ -237,7 +237,7 @@ func (c CmdReset) fiCmdWrite(fiw fiWriter) error { func init() { parser_registerCmd("reset ", CmdReset{}) } func (CmdReset) fiCmdRead(fir fiReader) (cmd Cmd, err error) { ez := &ezfir{fir: fir} - defer func() { err = ez.Defer() }() + defer ez.Defer(&err) // 'reset' SP <ref> LF c := CmdReset{RefName: trimLinePrefix(ez.ReadLine(), "reset ")} @@ -281,7 +281,7 @@ func (c CmdBlob) fiCmdWrite(fiw fiWriter) error { func init() { parser_registerCmd("blob\n", CmdBlob{}) } func (CmdBlob) fiCmdRead(fir fiReader) (cmd Cmd, err error) { ez := &ezfir{fir: fir} - defer func() { err = ez.Defer() }() + defer ez.Defer(&err) // 'blob' LF _ = ez.ReadLine() @@ -325,7 +325,7 @@ func (c CmdAlias) fiCmdWrite(fiw fiWriter) error { func init() { parser_registerCmd("alias\n", CmdCheckpoint{}) } func (CmdAlias) fiCmdRead(fir fiReader) (cmd Cmd, err error) { ez := &ezfir{fir: fir} - defer func() { err = ez.Defer() }() + defer ez.Defer(&err) // 'alias' LF _ = ez.ReadLine() @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Luke Shumaker <lukeshu@lukeshu.com> +// Copyright (C) 2017, 2021 Luke Shumaker <lukeshu@lukeshu.com> // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by @@ -51,7 +51,7 @@ type ezfir struct { var ezPanic = errors.New("everything is fine") -func (e *ezfir) Defer() error { +func (e *ezfir) Defer(err *error) { if e.err != nil { r := recover() if r == nil { @@ -60,9 +60,8 @@ func (e *ezfir) Defer() error { if r != ezPanic { panic(r) } - return e.err + *err = e.err } - return nil } func (e *ezfir) Errcheck(err error) { |