Skip to content
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 pkg/jsonpath/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion pkg/jsonpath/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 19 additions & 2 deletions web/src/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
[],
Expand Down Expand Up @@ -313,7 +316,7 @@ function Playground() {
onClick={getShareUrl}
disabled={shareUrlLoading}
>
Share
Short URL
</Button>
<div className="flex items-center gap-x-2 grow">
{shareUrl ? <CopyButton value={shareUrl} /> : null}
Expand All @@ -324,7 +327,21 @@ function Playground() {
</div>
</div>
</div>
{error && <Alert variant={"error"}>{error}</Alert>}
{error && (
<Alert onDismiss={clearError} variant={"error"}>
{error.split("\n").length > 1 ? (
<>
{error.split("\n")[0]}
<br />
<div className="text-left whitespace-pre">
<pre>{error.split("\n").slice(1).join("\n")}</pre>
</div>
</>
) : (
error
)}
</Alert>
)}
<div
style={{
display: "flex",
Expand Down
Binary file modified web/src/assets/wasm/lib.wasm
Binary file not shown.
27 changes: 0 additions & 27 deletions web/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,6 @@ h1 {
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
Loading