Skip to content

fix(analysis): raise ValueError instead of NameError when FIO command…#87

Open
andrewwhitecdw wants to merge 2 commits into
NVIDIA:mainfrom
andrewwhitecdw:sweep/bugfix-fio-nameerror
Open

fix(analysis): raise ValueError instead of NameError when FIO command…#87
andrewwhitecdw wants to merge 2 commits into
NVIDIA:mainfrom
andrewwhitecdw:sweep/bugfix-fio-nameerror

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

… missing

Summary

When bobber parse-results processes a FIO log that does not contain at least two /usr/bin/fio --rw... command lines, the tool is supposed to raise a clear ValueError. Instead it crashes with NameError: name 'log' is not defined, hiding the real problem from the user.

Root cause

In fio_command_details() (bobber/lib/analysis/common.py), the error message references a variable log that does not exist in the function scope (the function only receives log_contents, old_reads, and old_writes):

commands = re.findall(r'/usr/bin/fio --rw.*', log_contents)
if len(commands) < 2:
    raise ValueError(f'FIO command not found in {log} file!')

Evaluating the f-string raises NameError before the ValueError can be constructed, so callers see an unhelpful NameError traceback.

Fix

Drop the undefined filename reference from the message (the function has no access to the log filename):

raise ValueError('FIO command not found in the log file!')

Testing

  • Reproduced with uv run --with pyyaml python:
    • Before: fio_command_details('no fio commands here', {}, {}) raised NameError: name 'log' is not defined.
    • After: raises ValueError: FIO command not found in the log file! as intended.
  • Sanity-checked the happy path: parsing a log containing read/write fio commands still returns the expected parameter dicts.
  • pycodestyle bobber/lib/analysis/common.py passes (matches the lint step in .github/workflows/python-package.yml).
  • The full CI suite (wheel build + bobber build Docker image build) was not run locally as it requires Docker and GPU test infrastructure.

Why existing tests missed it

The repository has no unit tests for the parsing library; CI only lints and builds the package/Docker image, so this error path was never exercised.

… missing

## Summary

When `bobber parse-results` processes a FIO log that does not contain at
least two `/usr/bin/fio --rw...` command lines, the tool is supposed to
raise a clear `ValueError`. Instead it crashes with
`NameError: name 'log' is not defined`, hiding the real problem from the
user.

## Root cause

In `fio_command_details()` (`bobber/lib/analysis/common.py`), the error
message references a variable `log` that does not exist in the function
scope (the function only receives `log_contents`, `old_reads`, and
`old_writes`):

```python
commands = re.findall(r'/usr/bin/fio --rw.*', log_contents)
if len(commands) < 2:
    raise ValueError(f'FIO command not found in {log} file!')
```

Evaluating the f-string raises `NameError` before the `ValueError` can
be constructed, so callers see an unhelpful `NameError` traceback.

## Fix

Drop the undefined filename reference from the message (the function has
no access to the log filename):

```python
raise ValueError('FIO command not found in the log file!')
```

## Testing

- Reproduced with `uv run --with pyyaml python`:
  - Before: `fio_command_details('no fio commands here', {}, {})` raised
    `NameError: name 'log' is not defined`.
  - After: raises `ValueError: FIO command not found in the log file!`
    as intended.
- Sanity-checked the happy path: parsing a log containing read/write fio
  commands still returns the expected parameter dicts.
- `pycodestyle bobber/lib/analysis/common.py` passes (matches the lint
  step in `.github/workflows/python-package.yml`).
- The full CI suite (wheel build + `bobber build` Docker image build)
  was not run locally as it requires Docker and GPU test infrastructure.

## Why existing tests missed it

The repository has no unit tests for the parsing library; CI only lints
and builds the package/Docker image, so this error path was never
exercised.
Flags the case where `fio_command_details()` receives log contents with
fewer than two `/usr/bin/fio --rw...` command lines and crashed with
`NameError: name 'log' is not defined` instead of the intended
`ValueError`. Also sanity-checks that a valid read/write FIO log still
parses.

Red-green verification:
- With fix (HEAD): `uv run --with pytest pytest
  tests/test_fio_command_nameerror.py -q` -> 2 passed.
- Without fix (`git show HEAD~1:bobber/lib/analysis/common.py >
  bobber/lib/analysis/common.py`): same command -> 1 failed
  (NameError: name 'log' is not defined), 1 passed.
- Restored with `git checkout -- .`.
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.

1 participant