diff --git a/pkg/jsonpath/parser.go b/pkg/jsonpath/parser.go index 2a688fe..d8f15f6 100644 --- a/pkg/jsonpath/parser.go +++ b/pkg/jsonpath/parser.go @@ -55,7 +55,7 @@ func (p *JSONPath) parse() error { } func (p *JSONPath) parseFailure(target *token.TokenInfo, msg string) error { - return errors.New(p.tokenizer.ErrorTokenString(target, msg)) + return errors.New(p.tokenizer.ErrorString(target, msg)) } // peek returns true if the upcoming token matches the given token type. diff --git a/pkg/jsonpath/token/token.go b/pkg/jsonpath/token/token.go index 5b621df..2a0c0cb 100644 --- a/pkg/jsonpath/token/token.go +++ b/pkg/jsonpath/token/token.go @@ -315,7 +315,10 @@ func (t Tokenizer) ErrorString(target *TokenInfo, msg string) string { // Write the caret symbol pointing to the target token errorBuilder.WriteString(spaces) - dots := strings.Repeat(".", target.Len-1) + dots := "" + if target.Len > 0 { + dots = strings.Repeat(".", target.Len-1) + } errorBuilder.WriteString("^" + dots + "\n") return errorBuilder.String() diff --git a/web/src/Playground.tsx b/web/src/Playground.tsx index c955e2c..f8e756d 100644 --- a/web/src/Playground.tsx +++ b/web/src/Playground.tsx @@ -70,6 +70,9 @@ function Playground() { const [shareUrl, setShareUrl] = useState(""); const [shareUrlLoading, setShareUrlLoading] = useState(false); const isSmallScreen = useMediaQuery("(max-width: 768px)"); + const clearError = useCallback(() => { + setError(""); + }, []); const defaultLayout = useMemo( () => (isSmallScreen ? [20, 60, 20] : [30, 40, 30]), [], @@ -313,7 +316,7 @@ function Playground() { onClick={getShareUrl} disabled={shareUrlLoading} > - Share + Short URL
{error.split("\n").slice(1).join("\n")}
+