Make PEP 723 metadata diagnostics actionable - #1769
Conversation
75321f4 to
544f6af
Compare
A malformed PEP 723 block logged a warning that named no file, printed ten
frames of minified bundle internals, and reported a row index into the
reconstructed TOML rather than a line in the script. It read like an
extension crash while telling the user neither which file was wrong nor
where.
inline script metadata: failed to parse TOML in `# /// script` block:
[TomlError: Unterminated string at row 1, col 27, pos 26:
1> requires-python = ">=3.11
at TOMLParser.parseBasicString (dist/extension.js:45477:28)
... 9 more frames
inline script metadata in C:\src\app.py: invalid TOML in the
`# /// script` block (line 2): Unterminated string
Take an optional source label on readInlineScriptMetadata and thread it
through every diagnostic; readInlineScriptMetadataFromFile passes the
script path. Translate the TOML row into a real script line via the known
block offset, drop the payload-relative coordinates and caret excerpt, and
move the full error (with its stack) to the debug level for anyone
diagnosing the parser itself. Parsing behaviour is unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
544f6af to
cd7d214
Compare
|
🔒 Automated review in progress — Rich Chiodo (@rchiodo) is auto-reviewing this PR. |
|
Result: 🔴 Verification detailsVerification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified. Summary: Podman setup was declined or unavailable; isolated test execution was skipped. Test runs: none recorded. |
Rich Chiodo (rchiodo)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
| */ | ||
| export function readInlineScriptMetadata(scriptText: string): InlineScriptMetadata | undefined { | ||
| export function readInlineScriptMetadata(scriptText: string, source?: string): InlineScriptMetadata | undefined { | ||
| const where = source ? ` in ${source}` : ''; |
There was a problem hiding this comment.
Maybe add the space in the consuming strings?
There was a problem hiding this comment.
like in line 124 and 129? not sure if it's a good idea to put repetitive code in multiple places thorough, the space is only added when there's actual source exist do the check is done before it being consumed.
| // full error (with stack and excerpt) goes to the debug level for anyone | ||
| // diagnosing the parser itself. | ||
| const tomlRow = getTomlErrorRow(err); | ||
| const at = tomlRow === undefined ? '' : ` (line ${blockStartLine + 1 + tomlRow})`; |
There was a problem hiding this comment.
Same here
Summary
Make PEP 723 inline-script metadata failures easier to diagnose in the Python Environments output:
Parsing acceptance, environment provisioning, and interpreter routing are unchanged. This PR includes both commits from
fixInlineScriptIssues, including the formatting follow-up.