load_payloads: tolerate globbed-but-uncached payload files#440
Closed
MacrayBlackhand wants to merge 1 commit into
Closed
load_payloads: tolerate globbed-but-uncached payload files#440MacrayBlackhand wants to merge 1 commit into
MacrayBlackhand wants to merge 1 commit into
Conversation
scan_payload_dir only caches a payload .lua when its content matches the ["unitType"]="..." regex, but load_payloads globs all *.lua and reads the cache with a bare subscript -- so a globbed file that wasn't cached (e.g. an aircraft module whose payload file uses a syntax the regex doesn't match, such as the shipping F-100D) raises KeyError and aborts the entire mission load. Use dict.get() so an uncached path is simply skipped.
Collaborator
|
was faster, sorry |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
FlyingType.load_payloads() aborts the entire mission load with a KeyError
when a payload directory contains a *.lua file that scan_payload_dir()
globbed but did not cache.
The two halves of the payload machinery use mismatched guards:
a cache entry when the file content matches the regex
\["unitType"]\s*=\s*"([^"]*)(dcs/unittype.py, ~L108-122). A file whoseunitType is written in a form the regex doesn't match is globbed but never
cached.
a bare subscript (dcs/unittype.py:140):
For any globbed-but-uncached path, _payload_cache[path] raises KeyError,
which propagates out of load_payloads() and aborts loading the whole mission.
Concrete current motivating case: the shipping ED F-100D module ships
CoreMods/aircraft/F-100D/UnitPayloads/F-100D.lua. That directory is on the
payload search path, so the file globs -- but its content isn't matched by the
["unitType"] regex, so it isn't cached. The result: loading any mission that
references an F-100D crashes in load_payloads().
Relationship to #317
Issue #317 ("replace our lua parser with lupa?") diagnoses the same underlying
cause -- the regex-based payload scanner can't handle certain payload-file
syntaxes (the F-100D among them) -- and proposes a larger lupa-based parser
rewrite.
This PR is the small, complementary, defensive fix: it does not attempt to fix
the parser or make the uncacheable file parse. It only stops one
unparseable-but-globbed file from taking down the entire mission load, regardless
of whether or when the larger parser rewrite in #317 lands. A file the scanner
can't cache is simply skipped (which is already the intended outcome for a file
that doesn't match a unit) instead of raising.
Fix
One call, in load_payloads():
An uncached path -> .get() returns None -> None != cls.id -> the file is
skipped. Cached files are unaffected; nothing else changes.
Test
Added test_load_payloads_skips_globbed_but_uncached_file to
tests/test_unittype.py (matching the existing tmp_path/monkeypatch style).
It creates a payload directory containing:
shape), and
points the scanner at the temp directory, and asserts that load_payloads() does
not raise and still loads the valid payload. The test fails with KeyError
against the pre-fix bare subscript and passes with .get().