Skip to content

Properly expose project load errors in VS Code, improve error handling in WASM/JS #2476

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

Merged
merged 4 commits into from
Jun 3, 2025

Conversation

minestarks
Copy link
Member

@minestarks minestarks commented May 30, 2025

This PR improves how project loading and QIR generation errors are handled in the VS Code extension. Additionally, there are internal changes normalizing how we raise and handle errors coming from the WASM component.

User facing changes

Previously, whenever project load failed while performing some task, we would show a modal dialog. Additionally we would populate the Problems view with sticky "QDK command error:" errors.

  • Removed excessive modal dialogs on project load errors for tasks that don't need them:

    • Test explorer
    • Debugger
    • Copilot tools for Q#
      • Also, more detailed project load errors are communicated to Copilot so it can respond appropriately.
  • These user-invoked commands continue to show the modal dialog when project load fails:

    • Histogram
    • Show circuit
    • Generate QIR / Submit to Azure
    • Estimate
    • Generate documentation
  • Removed the sticky "QDK command error:" errors for project load, since the language service already reports those errors. We don't want to litter the Problems view with duplicates.

  • Kept the sticky errors for when QIR generation fails at runtime. These are runtime errors and therefore are not reported by the language service, so no risk of duplication.

  • Improved the contents of these modal error dialogs to be more user-friendly.

Internals

  • Added a new QdkDiagnostics class that properly extends JavaScript's Error type and contains VS Code-ish diagnostics

  • Many WASM functions use a string as an error type, which is really a JSON-serialized IQSharpError[] array. Given the limitations of wasm-bindgen, and also the fact that this error has to travel across worker threads, we can't really use a more sophisticated error type here.

  • So instead, we convert these into QdkDiagnostics in JavaScript.

  • To make sure the error type flows properly from the worker thread to the main thread, we serialize the errors to cloneable objects.

  • Going forward, when adding new WASM functions, we should try to conform to this pattern of error handling. WASM functions should throw IQSharpError[] strings wherever appropriate, and the appropriate wrappers should be used in JavaScript to convert it into a QdkDiagnostics.

Before/After

For my own sanity, here's a visual list of the places where error UX changed.

Project load error in Run / Debug

Before After
run_projectload_old run_projectload_new

Project load error in Histogram / Circuit / Estimate / QIR generation / Submit to Azure

Before After
histogram_projectload_old histogram_projectload_new

Project load error in Copilot Q# tools / Submit to Azure

Before After
copilot_projectload_old copilot_projectload_new

Project load error in Documentation generation

Before After
documentation_projectload_old documentation_projectload_new

Project load error in Test case run (vscode/src/language-service/testExplorer.ts)

Before After
test_projectload_old test_projectload_new

Runtime error in QIR generation

Before After
qirgen_runtimefail_old qirgen_runtimefail_new

Errors in Playground QIR/RIR panels

Before After
playground_runtimefail_old playground_runtimefail_new

@minestarks minestarks marked this pull request as ready for review June 2, 2025 16:36
@minestarks minestarks added this pull request to the merge queue Jun 3, 2025
Merged via the queue into main with commit 9c56278 Jun 3, 2025
19 checks passed
@minestarks minestarks deleted the minestarks/error-handling-project-load branch June 3, 2025 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants