Skip to content

petablint: report invalid input without tracebacks #611

Open

Description

@dweindl

petablint should never show a traceback for invalid input. Currently, several kinds of errors while loading a problem end in an unhandled exception. I ran petablint (main + #610) on a valid v2 problem with one thing broken per run:

Case v2 v1
YAML file not found FileNotFoundError traceback same
YAML syntax error PyYAML parser error traceback same
table file not found FileNotFoundError traceback AssertionError traceback
empty table file pandas.errors.EmptyDataError traceback same
model file not found FileNotFoundError traceback AssertionError traceback
invalid SBML ValueError traceback AssertionError traceback
remote table URL returns 404 urllib.error.HTTPError traceback not tested
non-numeric bound handled (pydantic) ValueError traceback

Handled without traceback in v2: YAML schema violations, unknown format_version, missing required columns (#610), and invalid values that pydantic catches (estimate=yes, non-numeric numbers, unknown distributions, invalid math, ...).

The pydantic-based reporting in v2 has further limitations:

  • Errors lack the table, file and row, e.g., Error in field(s) `time`: Input should be a valid number doesn't say whether this is the measurement or experiment table. Errors from model validators have an empty location: Error in field(s) : Value error, Lower bound must be less than or equal to upper bound.``
  • Loading stops at the first invalid row, so only one error is reported, even if several rows or tables are invalid. No lint checks run in that case.

Exceptions raised inside a v2 validation task are already converted into a CRITICAL validation issue, but the issue message includes the full traceback. Those are bugs in the linter rather than invalid input, so a traceback may be fine there, though we might want to label it as an internal error and ask users to report it.

Possible approach:

  1. In the library, raise a common exception type for invalid input while loading (e.g., a PetabLoadError base class, with MissingColumnsError as a subclass), including the file and, where applicable, table and row. Wrap OSError, URLError, YAML, pandas and model-loading errors accordingly.
  2. In petablint, catch that base class and pydantic ValidationError, log the message, and exit with 1. Optionally, catch any other exception as "internal error, please report", with the traceback only shown with -v.
  3. Report pydantic errors with table, file and row number.
  4. Separately: collect all row-level errors instead of failing on the first one. This overlaps with lenient loading discussed in v2: Update validator #369.

Regarding row numbers (see also #366): they need to refer to the file, not to an internal DataFrame index. In v1, Problem.from_yaml concatenates multiple tables of the same type (concat_tables, with ignore_index=True for measurement tables), so the row index in messages such as Mismatch of noise parameter overrides in: ... Name: 21 refers to the concatenated table and doesn't identify the file or the line in it. In v2, tables are kept per file, so the row number would have to be determined when loading each table, before tables are combined (e.g., via Problem.measurement_df). Also, a 0-based DataFrame index differs from the line number in the file (header, 1-based).

Relates to #369, #366, #217, #219.

🤖 Generated by Claude Code (AI agent).

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions