fix(Engine): don't crash on a duplicate key in a simple dictionary attribute - #2018
Merged
Conversation
…tribute A simplestringdictionary/simpleobjectdictionary attribute with a repeated key (e.g. "to"=to;"to"=to in a third-party library's editor <validvalues> template) threw an uncaught ArgumentException from Dictionary.Add during load, instead of being recorded as a normal load error the way a missing '=' already is a few lines above. In an AOT-trimmed build (WasmEditor) this surfaced to the user as a raw, untranslated exception message like "Argument_AddingDuplicateWithKey, "to"" instead of the friendly "Failed to load game due to the following errors" list. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
Follow-up found while investigating a user report about the RunCommand.aslx library (from EightOne, a popular community library): loading a game that includes it fails with
Error: Argument_AddingDuplicateWithKey, "to"instead of the friendly "Failed to load game due to the following errors" message.Root cause
RunCommand.aslx'sEditorScriptsScriptsRunCommandPrePositionstemplate lists the"to"mapping twice:That string is parsed as a
simplestringdictionaryeditor<validvalues>attribute bySimpleStringDictionaryLoader.Load(src/Engine/GameLoader/AttributeLoaders.cs), which calledQuestDictionary<string>.Add(key, value)for every entry with no duplicate check.Dictionary.AddthrowsArgumentException("Argument_AddingDuplicateWithKey") on a repeated key, and nothing between there and the WASM boundary (WasmEditorBridge.Initialise) catches that specific exception type as a normal load error — it falls into the genericcatch (Exception ex)instead, and because WasmEditor is AOT-trimmed,ex.Messageloses its resource string and becomes the bare, untranslated resource key.This is a bug in that particular library file's data (a copy-paste duplicate), not something introduced by quest itself — but the engine crashing ungracefully on malformed dictionary data, with a cryptic message, is a real robustness gap: any third-party library (or hand-edited game) with a duplicate key in a
simplestringdictionary/simpleobjectdictionaryattribute hits the same crash today.Fix
SimpleStringDictionaryLoaderand its siblingSimpleObjectDictionaryLoader(same copy-pasted parsing loop, same latent bug) now check for a duplicate key before adding and record a normal, friendly load error instead — exactly mirroring the existing handling for a missing=a few lines above in the same method. The game still fails to load (the dictionary is genuinely ambiguous), but with a clear, actionable message pointing at the offending element/attribute instead of a raw exception.Test plan
AttributeLoaderTests.cswith regression tests for both loaders: a duplicate key now produces a friendlyWorldModel.Errorsentry (Duplicate key '"to"' in dictionary element ...) instead of an uncaught exception — the assertion text matches the user's exact reported quoted-key format.dotnet build --configuration Release(full solution) anddotnet test --configuration Release(294+ tests) both pass.🤖 Generated with Claude Code