Skip to content

gallery: a DDS preview that can't be converted is a 500, not a 404 - #6694

Open
dukefissura wants to merge 2 commits into
ItsNotRexed:mainfrom
dukefissura:gallery-dds-preview-error
Open

dukefissura wants to merge 2 commits into
ItsNotRexed:mainfrom
dukefissura:gallery-dds-preview-error

Conversation

@dukefissura

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: GALLERY-DDS-PREVIEW-ERROR (in #6603)

Depends on: #6481. This branch is built on it because both change the DDS preview block, so it shows that commit too; only the second commit (4a14059) is this PR. It complements #5120, which makes dds_png raise its decoder errors: this change is what reports them.

What and why

When dds_png couldn't convert a .dds (or couldn't be imported), tools/gallery.py swallowed the exception (except Exception: pass) and fell through to the PNG lookup, which answered 404 Texture not found for a texture that is there. The decoder's reason was lost, and the server logs nothing because log_message is silenced. Reproduced with a .dds whose header can't be decoded: HTTP/1.0 404 Texture not found.

Now, when the .dds exists:

  • a failed conversion is a 500 DDS preview failed, with the exception type and message in the escaped HTML body (send_error's explain argument), not in the status line;
  • a missing dds_png is a 501.

A .png request with no .dds next to it is still a plain 404.

Tested

Linux, Python 3.13.18, CPU only, no GPU or driver involved, no game files (the test writes a .dds with an empty header by hand).

  • python -I tests/test_gallery.py: 22/22 on top of gallery: send the DDS preview no-cache, like every other response #6481 (main 4beffda).
  • test_a_dds_preview_that_cannot_be_converted_says_so: the broken .dds gets a 500 with DdsError in the body, the same request with dds_png unavailable gets a 501, and a missing texture is still a 404. It fails before the change (404 != 500).
  • python -m compileall and git diff --check are clean.

AI-assisted: yes (Claude)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not applicable: no translator change.)

dukefissura and others added 2 commits November 23, 2026 11:21
tools/gallery.py converts a .dds to a PNG preview at /textures/<stem>.png and sent it with
Cache-Control: max-age=86400, while _send_file sends every other file no-cache. The preview URL
never changes, so after the .dds is exported again the Studio kept showing the old picture for up to
a day. The preview is now no-cache too.

tests/test_gallery.py: test_dds_preview_is_not_cached_across_reexports checks the header on the
DDS preview and on a plain PNG; it fails before the change ('max-age=86400' != 'no-cache').

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Fi5BEBqGPiXnY67f9mzu13
…he error, not a 404

When dds_png could not convert a .dds (or could not be imported), the handler swallowed the
exception and fell through to the PNG lookup, which answered 404 "Texture not found" for a texture
that is there. The decoder's reason was lost, and the server logs nothing (log_message is quiet).

Now a .dds that exists but cannot be converted is a 500 "DDS preview failed", with the exception
type and message in the escaped HTML body rather than the status line, and a missing dds_png is a
501. A .png with no .dds next to it is still a 404. Built on the no-cache preview change (ItsNotRexed#6481),
which touches the lines right above.

tests/test_gallery.py: a hand-made .dds with an empty header gets 500 with DdsError in the body, the
same request with dds_png unavailable gets 501, and a missing texture still 404. It fails before the
change (404 != 500).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Fi5BEBqGPiXnY67f9mzu13
@memorypressure

Copy link
Copy Markdown

All 22 tests pass at the head (python -I, live localhost server); the two new tests fail on current main, pinning both the 500-with-reason and the no-cache behavior. 501 for missing decoder, 404 preserved for absent .dds, decoder reason only in the escaped HTML body — behavior is right. One process gap: the branch reports no CI checks — re-trigger before merge. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

gallery.py's do_GET now treats an existing .dds whose preview fails as a real preview error: a missing dds_png module returns 501 "DDS preview unavailable", and any exception from dds_file_to_png_bytes() returns 500 "DDS preview failed" with the escaped DdsError type and message in the body. Successful previews drop Cache-Control: max-age=86400 for no-cache. Tests assert the PNG header, both error codes, a plain 404 for a texture with no .dds, and the new cache header on both preview and source responses.

Why merge

A broken re-export previously looked like a missing texture and stayed cached in browsers after the .dds was fixed; errors are now explicit and previews revalidate.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary

gallery.py's do_GET now treats an existing .dds whose preview fails as a real preview error: a missing dds_png module returns 501 "DDS preview unavailable", and any exception from dds_file_to_png_bytes() returns 500 "DDS preview failed" with the escaped DdsError type and message in the body. Successful previews drop Cache-Control: max-age=86400 for no-cache. Tests assert the PNG header, both error codes, a plain 404 for a texture with no .dds, and the new cache header on both preview and source responses.

Why merge

A broken re-export previously looked like a missing texture and stayed cached in browsers after the .dds was fixed; errors are now explicit and previews revalidate.

Verdict: Approve

@airp1ane

Copy link
Copy Markdown
Contributor

Tested 4a14059 on Windows 11, Python 3.15.2, NVIDIA RTX 4060 Ti (driver 621.24; CPU-only checks, no game files, no GPU/llvm-mc/MSVC used): pass.

Ran the test files this PR adds or changes, from a clean checkout of the PR head: test_gallery.py - all exit 0.

AI-assisted (Claude Code).

@rideinstead

Copy link
Copy Markdown

✅ Automated security review: CLEAN (commit 4a14059f)

  • No findings.

Scope: static analysis of added diff lines only; no code was executed. Please review findings manually.

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.

5 participants