Summary
When pyqasm.loads() fails to parse, the ValidationError message is "Failed to parse OpenQASM string: " with nothing after the colon. The ANTLR diagnostic that says what is wrong (line 3:10 no viable alternative at input 'rx(pi/2q') goes to stderr only, so a service that surfaces str(exc) to a user gives them an empty reason.
Repro (pyqasm 1.2.1, openqasm3 1.0.1)
import pyqasm
try:
pyqasm.loads("OPENQASM 3.0;\nqubit q;\nrx(pi / 2 q;\n")
except Exception as exc:
print(repr(str(exc)))
# prints: 'Failed to parse OpenQASM string: '
# stderr: line 3:10 no viable alternative at input 'rx(pi/2q'
openqasm3.parser.QASM3ParsingError is raised with no message (raise QASM3ParsingError() from exc in openqasm3/parser.py:107), so {err} formats as empty.
Suggestion
Capture the ANTLR error listener output (line, column, message) and put it in the ValidationError message, e.g. Failed to parse OpenQASM string: line 3:10 no viable alternative at input 'rx(pi/2q'. Line and column would also let callers point at the offending statement.
Summary
When
pyqasm.loads()fails to parse, theValidationErrormessage is"Failed to parse OpenQASM string: "with nothing after the colon. The ANTLR diagnostic that says what is wrong (line 3:10 no viable alternative at input 'rx(pi/2q') goes to stderr only, so a service that surfacesstr(exc)to a user gives them an empty reason.Repro (pyqasm 1.2.1, openqasm3 1.0.1)
openqasm3.parser.QASM3ParsingErroris raised with no message (raise QASM3ParsingError() from excinopenqasm3/parser.py:107), so{err}formats as empty.Suggestion
Capture the ANTLR error listener output (line, column, message) and put it in the
ValidationErrormessage, e.g.Failed to parse OpenQASM string: line 3:10 no viable alternative at input 'rx(pi/2q'. Line and column would also let callers point at the offending statement.