summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2021-05-01 02:35:29 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2021-05-01 02:35:29 -0600
commit554090886c69cba9b3389d3ee86f61292aafaed1 (patch)
treec760fe48a96a243a3216f251ec815c2ab43a9ffb
parent5f64323918520e048cc02eb522aeaf7f814d611b (diff)
improve error messages
-rw-r--r--cmd_command.go20
-rw-r--r--ez.go4
-rw-r--r--util.go4
3 files changed, 14 insertions, 14 deletions
diff --git a/cmd_command.go b/cmd_command.go
index d66c9ce..de0d4c5 100644
--- a/cmd_command.go
+++ b/cmd_command.go
@@ -83,7 +83,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 ez.Defer(&err)
+ defer ez.Defer("commit", &err)
// 'commit' SP <ref> LF
c := CmdCommit{Ref: trimLinePrefix(ez.ReadLine(), "commit ")}
@@ -108,7 +108,7 @@ func (CmdCommit) fiCmdRead(fir fiReader) (cmd Cmd, err error) {
// 'committer' (SP <name>)? SP LT <email> GT SP <when> LF
if !strings.HasPrefix(ez.PeekLine(), "committer ") {
- ez.Errcheck(errors.Errorf("commit: expected committer command: %q", ez.ReadLine()))
+ ez.Errcheck(errors.Errorf("expected committer command: %q", ez.ReadLine()))
}
c.Committer, err = ParseIdent(trimLinePrefix(ez.ReadLine(), "committer "))
ez.Errcheck(err)
@@ -195,7 +195,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 ez.Defer(&err)
+ defer ez.Defer("tag", &err)
// 'tag' SP <tagname> LF
c := CmdTag{TagName: trimLinePrefix(ez.ReadLine(), "tag ")}
@@ -213,7 +213,7 @@ func (CmdTag) fiCmdRead(fir fiReader) (cmd Cmd, err error) {
// 'from' SP <commit-ish> LF
if !strings.HasPrefix(ez.PeekLine(), "from ") {
- ez.Errcheck(errors.Errorf("tag: expected from command: %q", ez.ReadLine()))
+ ez.Errcheck(errors.Errorf("expected from command: %q", ez.ReadLine()))
}
c.CommitIsh = trimLinePrefix(ez.ReadLine(), "from ")
@@ -224,7 +224,7 @@ func (CmdTag) fiCmdRead(fir fiReader) (cmd Cmd, err error) {
// 'tagger' (SP <name>)? SP LT <email> GT SP <when> LF
if !strings.HasPrefix(ez.PeekLine(), "tagger ") {
- ez.Errcheck(errors.Errorf("tag: expected tagger command: %q", ez.ReadLine()))
+ ez.Errcheck(errors.Errorf("expected tagger command: %q", ez.ReadLine()))
}
c.Tagger, err = ParseIdent(trimLinePrefix(ez.ReadLine(), "tagger "))
ez.Errcheck(err)
@@ -261,7 +261,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 ez.Defer(&err)
+ defer ez.Defer("reset", &err)
// 'reset' SP <ref> LF
c := CmdReset{RefName: trimLinePrefix(ez.ReadLine(), "reset ")}
@@ -305,7 +305,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 ez.Defer(&err)
+ defer ez.Defer("blob", &err)
// 'blob' LF
_ = ez.ReadLine()
@@ -349,7 +349,7 @@ func (c CmdAlias) fiCmdWrite(fiw fiWriter) error {
func init() { parser_registerCmd("alias\n", CmdAlias{}) }
func (CmdAlias) fiCmdRead(fir fiReader) (cmd Cmd, err error) {
ez := &ezfir{fir: fir}
- defer ez.Defer(&err)
+ defer ez.Defer("alias", &err)
// 'alias' LF
_ = ez.ReadLine()
@@ -357,14 +357,14 @@ func (CmdAlias) fiCmdRead(fir fiReader) (cmd Cmd, err error) {
// mark
if !strings.HasPrefix(ez.PeekLine(), "mark :") {
- ez.Errcheck(errors.Errorf("alias: expected mark command: %q", ez.ReadLine()))
+ ez.Errcheck(errors.Errorf("expected mark command: %q", ez.ReadLine()))
}
c.Mark, err = strconv.Atoi(trimLinePrefix(ez.ReadLine(), "mark :"))
ez.Errcheck(err)
// 'to' SP <commit-ish LF
if !strings.HasPrefix(ez.PeekLine(), "to ") {
- ez.Errcheck(errors.Errorf("alias: expected to command: %q", ez.ReadLine()))
+ ez.Errcheck(errors.Errorf("expected to command: %q", ez.ReadLine()))
}
c.CommitIsh = trimLinePrefix(ez.ReadLine(), "to ")
diff --git a/ez.go b/ez.go
index a1dbfca..79399a8 100644
--- a/ez.go
+++ b/ez.go
@@ -51,7 +51,7 @@ type ezfir struct {
var ezPanic = errors.New("everything is fine")
-func (e *ezfir) Defer(err *error) {
+func (e *ezfir) Defer(str string, err *error) {
if e.err != nil {
r := recover()
if r == nil {
@@ -60,7 +60,7 @@ func (e *ezfir) Defer(err *error) {
if r != ezPanic {
panic(r)
}
- *err = e.err
+ *err = errors.Wrap(e.err, str)
}
}
diff --git a/util.go b/util.go
index 544818e..d041168 100644
--- a/util.go
+++ b/util.go
@@ -35,12 +35,12 @@ func trimLinePrefix(line string, prefix string) string {
func parse_data(line string) (data string, err error) {
nl := strings.IndexByte(line, '\n')
if nl < 0 {
- return "", errors.Errorf("data: expected newline: %q", data)
+ return "", errors.Errorf("data: expected newline: %q", line)
}
head := line[:nl+1]
rest := line[nl+1:]
if !strings.HasPrefix(head, "data ") {
- return "", errors.Errorf("data: could not parse: %q", data)
+ return "", errors.Errorf("data: could not parse: %q", line)
}
if strings.HasPrefix(head, "data <<") {
// Delimited format