Skip to content

d3d12_guid_sites: an image, --header or --json path it cannot read is one ERROR line and exit 2 - #5737

Open
evilclanker9000 wants to merge 1 commit into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/5-guid-sites-paths
Open

evilclanker9000 wants to merge 1 commit into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/5-guid-sites-paths

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

tools/d3d12_guid_sites.py reports an unreadable path as one line, where it used to end in a traceback or silently say nothing.

What and why

Path Before After
an image FileNotFoundError traceback: the try in main() catches (ValueError, struct.error) (a bad PE) only, so scan()'s open() escapes ERROR: cannot read <path>: <reason>, exit 2
--header if header and os.path.isfile(header) dropped a path that is not a file, so the scan printed 0 known GUIDs and every interface came out UNKNOWN ERROR: cannot read <path>: <reason>, exit 2 (the default SDK header still just means "no header", as before)
--json the open(args.json, "w") caught nothing ERROR: cannot write <path>: <reason>, exit 2

The wording and the exit code are tools/d3d12_iid_scan.py's (ERROR: cannot read <path>: <reason>, exit 2), so two tools that read the same images fail the same way. The module docstring now says so too.

Test

python -I tests/test_d3d12_guid_sites.py — new test_unreadable_paths_are_one_error_line runs the CLI three times (missing image, missing --header, --json into a missing folder) and asserts exit 2, exactly one ERROR: line on stderr, and no Traceback. All fixtures are hand-built PE32+ images from the test's own pe32plus() helper: no game files, no Windows SDK, no GPU.

Before (tests/test_d3d12_guid_sites.py at 561b65a83, tool unchanged):

Ran 8 tests in 0.259s
FAILED (failures=1)
File "tools/d3d12_guid_sites.py", line 270, in scan
    with open(path, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: '...\nope.dll'

After:

Ran 8 tests in 0.396s
OK

The three cases by hand:

$ python -I tools/d3d12_guid_sites.py <scratch>\missing.dll --header <scratch>\empty.h
exit=2  ERROR: cannot read <scratch>\missing.dll: No such file or directory
$ python -I tools/d3d12_guid_sites.py <scratch>\ok.dll --header <scratch>\nope.h
exit=2  ERROR: cannot read <scratch>\nope.h: No such file or directory
$ python -I tools/d3d12_guid_sites.py <scratch>\ok.dll --header <scratch>\empty.h --json <scratch>\no_dir\out.json
exit=2  ERROR: cannot write <scratch>\no_dir\out.json: No such file or directory

python -m compileall -q tools tests is clean.

GPU

No GPU needed; nothing here touches the runtime or the translator.

Notes

  • A --header path that does not exist is now an error. That is the one behaviour change: it used to be treated as "no header". Keeping it silent is what makes a mistyped --header report every interface as UNKNOWN without a word, and --known, --json and the sibling d3d12_iid_scan all fail on a bad argument, so I chose consistency. Only a header given explicitly errors: default_header() returning None (no Windows SDK installed) still just means "no known IIDs".
  • tests/test_d3d12_guid_sites.py:test_cli used the nonexistent path <tmp>/none.h as a shortcut for "no known IIDs"; it now writes an empty <tmp>/none.h instead, which is the same thing without the new error.
  • I left the == <image>: skipped (...) line for a file that is readable but not a PE image alone: that is content, not a path, and the scan can go on to the next image.

Task: EGEN-GUID-SITES-PATHS (posted as a finding: in #5581).

AI-assisted.

… not a traceback

The image loop catches (ValueError, struct.error) only, so a mistyped image path ends in FileNotFoundError; --header that is not a file was dropped by os.path.isfile() and the scan reported every interface as UNKNOWN; the --json write caught nothing. All three now print one ERROR line and return 2, as tools/d3d12_iid_scan.py does.

Test: tests/test_d3d12_guid_sites.py (hand-built PE32+ fixtures, no game files).

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 2617077 (base 561b65a).

  • git diff --check clean.
  • python -I -m pytest tests/test_d3d12_guid_sites.py -q -> 8 passed.
  • Covers an unreadable image, --header and --json: one ERROR: line, exit 2, no traceback. The t6 test now uses an existing empty header, matching that a missing --header is an error.
  • default_header() only returns an existing file, so a machine without the SDK is unaffected.

Verdict: merge; this supersedes #5735 (close that one as the duplicate).

@milas6669

Copy link
Copy Markdown

Tested 26170778 on Windows 11 (10.0.26200), CPython 3.13, no GPU, no game data: pass.

python -I tests/test_d3d12_guid_sites.py
Ran 8 tests in 0.365s — OK

Negative control. With main's tools/d3d12_guid_sites.py and this branch's test file:

FAIL: test_unreadable_paths_are_one_error_line
AssertionError: 1 != 2 : image: Traceback (most recent call last):

so the traceback is really there on main, and the guard removes it rather than papering over a case that never fired.

The messages use {e.strerror or e} with the plain path, which is the same point that broke four other tools on Windows (#5760) — clean here.

One thing worth resolving before review: #5735 (same author, 20 seconds earlier) is a strict subset of this — the same image and --json guards without the --header one, and without its test. This PR is the one to keep; closing #5735 would leave one PR per fix in the queue.

AI-assisted.

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.

3 participants