Skip to content

fix: raise ValidationError for empty OpenQASM loads() - #451

Open
tonycoder-hub wants to merge 1 commit into
qBraid:mainfrom
tonycoder-hub:fix/loads-empty-validation-error
Open

tonycoder-hub wants to merge 1 commit into
qBraid:mainfrom
tonycoder-hub:fix/loads-empty-validation-error

Conversation

@tonycoder-hub

Copy link
Copy Markdown

Summary of changes

openqasm3.parse("") (and whitespace-only input) raises AttributeError ('NoneType' object has no attribute 'line') instead of QASM3ParsingError. pyqasm.loads() only caught QASM3ParsingError, so empty strings bubbled up as an unexpected AttributeError.

This PR also catches AttributeError from openqasm3.parse and maps it to ValidationError, matching other unparseable-string failures. Header-only programs (OPENQASM 3.0;\n) still load successfully.

Fixes #437

@argus-eye

argus-eye Bot commented Oct 12, 2026

Copy link
Copy Markdown

Argus review

Auto-review is off for this repo. Tick the box below to run a review on this PR.

  • Trigger Argus review

Estimated cost

  • Files changed: 2
  • Diff lines (±): 18
  • Historical avg: ~350.7k tokens · ~$1.38 · across last 13 review(s)

Tip: you can also comment @argus-eye review at any time.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: qBraid/pyqasm/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eb28d3ba-b225-4353-9bea-864b2e7cfcf8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@tonycoder-hub
tonycoder-hub force-pushed the fix/loads-empty-validation-error branch from 62f9ee5 to 8292778 Compare October 12, 2026 05:48
@TheGupta2012

TheGupta2012 commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Hi @tonycoder-hub , thanks for fixing this! The changes lgtm. Can you please fix the format job in CI and add a CHANGELOG entry? Should be good to merge post that

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@tonycoder-hub
tonycoder-hub force-pushed the fix/loads-empty-validation-error branch from 8292778 to cb1d0d5 Compare October 12, 2026 09:11
openqasm3.parse raises AttributeError (not QASM3ParsingError) for
empty or whitespace-only input when an internal span is None. Catch
that and map it to ValidationError like other parse failures.

Signed-off-by: Tony Coder <407243179@qq.com>
@tonycoder-hub
tonycoder-hub force-pushed the fix/loads-empty-validation-error branch from cb1d0d5 to 89b0e5e Compare October 12, 2026 11:14
@tonycoder-hub

Copy link
Copy Markdown
Author

Thanks @TheGupta2012 — format (trailing newlines) is fixed and I've added a CHANGELOG.md Unreleased Fixed entry for this PR. Please take another look when you have a moment.

This branch has not been deployed

No deployments
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.

loads("") raises AttributeError instead of ValidationError

3 participants