Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downgrade kong, to restore error handling/printing #272

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
cloud.google.com/go v0.110.8
github.com/alecthomas/kong v0.8.0
github.com/alecthomas/kong v0.7.1
github.com/jotaen/genie v0.0.1
github.com/jotaen/kong-completion v0.0.5
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cloud.google.com/go v0.110.8 h1:tyNdfIxjzaWctIiLYOTalaLKZ17SI44SKFW26QbOhME=
cloud.google.com/go v0.110.8/go.mod h1:Iz8AkXJf1qmxC3Oxoep8R1T36w8B92yU29PcBhHO5fk=
github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0=
github.com/alecthomas/assert/v2 v2.1.0/go.mod h1:b/+1DI2Q6NckYi+3mXyH3wFb8qG37K/DuK80n7WefXA=
github.com/alecthomas/kong v0.8.0 h1:ryDCzutfIqJPnNn0omnrgHLbAggDQM2VWHikE1xqK7s=
github.com/alecthomas/kong v0.8.0/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4=
github.com/alecthomas/kong v0.7.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
github.com/alecthomas/repr v0.1.0/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
22 changes: 22 additions & 0 deletions klog/app/cli/main/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ func TestHandleInputFiles(t *testing.T) {
assert.True(t, strings.Contains(out[1], "#foo 2h"), out)
}

func TestPrintAppErrors(t *testing.T) {
out := (&Env{
files: map[string]string{
"invalid.klg": "2020-01-01asdf",
"valid.klg": "2020-01-01",
},
}).run(
[]string{"print", "invalid.klg"},
[]string{"start", "valid.klg"},
[]string{"start", "valid.klg"},
)
// Out 0 should contain pretty-printed parsing errors.
assert.True(t, strings.Contains(out[0], "ERROR in line 1:"), out)
assert.True(t, strings.Contains(out[0], "2020-01-01asdf"), out)
assert.True(t, strings.Contains(out[0], "^^^^^^^^^^^^^^"), out)
assert.True(t, strings.Contains(out[0], "Invalid date"), out)
// Out 1 should go through without errors.
// Out 2 should then display logical error, since there is an open-range already.
assert.True(t, strings.Contains(out[2], "Error: Manipulation failed"), out)
assert.True(t, strings.Contains(out[2], "There is already an open range in this record"), out)
}

func TestBookmarkFile(t *testing.T) {
klog := &Env{
files: map[string]string{
Expand Down
3 changes: 2 additions & 1 deletion klog/app/cli/main/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package klog

import (
"github.com/jotaen/klog/klog/app"
"github.com/jotaen/klog/klog/app/cli/lib"
"github.com/jotaen/klog/klog/app/cli/lib/terminalformat"
"io"
"os"
Expand Down Expand Up @@ -42,7 +43,7 @@ func (e *Env) run(invocation ...[]string) []string {

_ = w.Close()
if runErr != nil {
outs[i] = runErr.Error()
outs[i] = lib.PrettifyError(runErr, false).Error()
continue
}
out, _ := io.ReadAll(r)
Expand Down
4 changes: 2 additions & 2 deletions klog/app/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ func NewParserErrors(errs []txt.Error) ParserErrors {
}

func (pe parserErrors) Error() string {
return fmt.Sprintf("%d parsing errors", len(pe.errors))
return fmt.Sprintf("%d parsing error(s)", len(pe.errors))
}

func (pe parserErrors) Details() string {
return fmt.Sprintf("%d parsing errors", len(pe.errors))
return fmt.Sprintf("%d parsing error(s)", len(pe.errors))
}

func (pe parserErrors) Original() error {
Expand Down
Loading