Skip to content

[Bug]: A malformed naming pattern escapes loads as a raw ValueError or IndexError #38

Description

@fedonman

Bug Description

A naming: pattern in a .qp schema: block is applied lazily, so a malformed one fails when the first bus path resolves through it. _resolve_bus_path narrows its except to (AttributeError, KeyError), which catches only the unknown-placeholder case. A malformed format string, a positional placeholder, or a format spec the substituted text cannot satisfy all raise out of loads unwrapped, with no line number.

Minimal Reproducible Example

import qprogram as qp

for pattern in ("{", "{0}", "{index:d}"):
    body = f'#!QProgram 1.0\n\nschema:\n  naming: "{pattern}"\n  element q:\n    drive info=IQ\n\nbody:\n  play q[0].drive "p"\n'
    qp.loads(body)

Expected Behavior

A ParseError on the naming: line, or on the bus-path line, the way an unknown placeholder already reports: Line 7: bus path 'q[0].drive' does not resolve against the program schema: 'foo'.

Actual Behavior

ValueError: Single '{' encountered in format string
IndexError: Replacement index 0 out of range for positional args tuple
ValueError: Unknown format code 'd' for object of type 'str'

.qp Text

#!QProgram 1.0

schema:
  naming: "{0}"
  element q:
    drive info=IQ

body:
  play q[0].drive "p"

System Information

qprogram 0.1.0
python   3.14.7 | Linux-6.18.33.2-microsoft-standard-WSL2-x86_64-with-glibc2.43
vendors  none

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

    serializationTouches the .qp writer, parser, registry and grammar

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions