Repository navigation
fix(repl): print every line of a usage error at the prompt - #1027
Merged
Merged
Conversation
A repository or notebook command given wrong arguments returns its usage as a *UsageError, whose Error() is only the first line; the terminal loop printed that line alone, leaving out the line saying what was wrong, while the Jupyter kernel's traceback showed both. The loop now prints every line the error holds, the first under the error prefix as before. Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Contributor
Author
There was a problem hiding this comment.
🔍 Devin Review: 2 flags
Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
Co-Authored-By: jason.han <hanhuijun@gmail.com>
5 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
The terminal prompt printed only the first line of a multi-line usage error. A repository or notebook
%load,%repo,%projectsor%publishgiven wrong arguments answers with a*repl.UsageErrorwhoseLineshold the usage line and the line saying what was wrong;UsageError.Error()isLines[0]alone, andrepl.Loopprinted"error: " + merr.Error(). So%load --id xshowed the usage and dropped--id is not an option of %load, while the Jupyter kernel, which reportsexecError("UsageError", usage.Error(), usage.Lines), showed both.Two conventions coexist in the meta handlers.
%render,%vizand%render-documentreturn their usage lines as output (metaRender:return usage, false, nil), so the loop already printed them whole;*UsageErrorthere is what the typed APIs (Session.Render,Viz,RenderDocument) return to callers like the kernel. The repository and notebook commands instead return*UsageErroras the meta error (usageError(...)inrepository.go,parseLoadArgsinnotebook.go), which is what the kernel's%projects now→UsageErrortest anddocs/reference/jupyter-kernel.md("a%command given wrong arguments is aUsageErrorwhose traceback is the command's usage") rely on. Moving those handlers to the output convention would turn the kernel'sUsageErrorinto plain stdout, so the fix is on the terminal side:repl.Loopnow prints every line of a*UsageErrorthroughmetaErrorLines— the first under theerror:prefix, as before and as the kernel's value is; the rest as they are, as the kernel's traceback shows them. Any other meta error prints as it did.UsageError.Error()is unchanged, so the kernel's output and its tests are untouched.No other consumer loses lines:
cmd/sysmlreachesRunMetaonly throughrepl.Loop, and the referee's%eval inpath never produces aUsageError.How it was verified
New
TestLoopPrintsEveryLineOfAUsageErrorininternal/frontend/repl/repository_test.godrives%load --id x,%load --id=a --id=band%projects nowthroughrepl.Loopand pins the exact lines. No existing test pinned the one-line terminal output; the kernel tests (internal/frontend/jupyter/{repository,replengine}_test.go) still pass unchanged.%load --id xat the prompt, before:after:
Gates run locally:
gofmt -l .(empty),go build ./...,go vet ./...,make lint,go test -race -count=1 ./internal/frontend/repl/... ./internal/frontend/jupyter/...,go test ./...,python3 scripts/changelog.py check,python3 scripts/check-doc-ids.py.Checklist
make testandmake lintpass locallyUsageError; the prompt's output needed no new textchanges/unreleased/<slug>.<section>.md, not as an edit toCHANGELOG.mdmake docs-countsrun if a gate count moved (no gate count moved)F4,K5) in the body, docs, or changelog