Skip to content

loads("") raises AttributeError instead of ValidationError #437

Description

@ryanhill1

Summary

pyqasm.loads("") raises AttributeError: 'NoneType' object has no attribute 'line' instead of a ValidationError. Whitespace-only input does the same. Every other unparseable string raises ValidationError("Failed to parse OpenQASM string: ..."), so a caller that catches PyQasmError to reject bad input lets this one through as a crash.

Repro (pyqasm 1.2.1, openqasm3 1.0.1, Python 3.12)

import pyqasm
pyqasm.loads("")        # AttributeError: 'NoneType' object has no attribute 'line'
pyqasm.loads("   \n")   # same
pyqasm.loads("this is not qasm")  # ValidationError, as expected

Expected

ValidationError, like any other program the parser cannot read. loads("OPENQASM 3.0;\n") already returns an empty module, so the empty-string case is the only one that is neither a module nor a ValidationError.

Related: #388 covers bare expression statements reaching the same AttributeError; this one is the empty / whitespace-only input.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions