[#51] Clear error for duplicate SerializedFile/archive names#104
Merged
Conversation
Analyze only supports a single build at a time. A second SerializedFile or archive with a name already processed used to fail with a raw 'UNIQUE constraint failed' SQLite error (only visible with -v), and two archives sharing a name were silently recorded as duplicate rows. Detect these cases and report a distinctive, self-contained one-line message, skipping the offending file/archive and continuing. Enforce unique archive names at the schema level (bump user_version to 6) and add tests plus docs.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #51 by detecting duplicate SerializedFile and archive names during analyze, replacing raw SQLite UNIQUE-constraint failures (or silent ambiguity) with a clear, documented, one-line skip message while continuing the run and counting the input as failed.
Changes:
- Introduces
AnalyzeDuplicateExceptionand surfaces it inAnalyzerTool/SerializedFileParserto print a consistent “Duplicate … name …” message (not gated on-v) and continue. - Adds in-memory duplicate detection in
SerializedFileSQLiteWriterto reject duplicates before inserts/transactions. - Enforces archive-name uniqueness in the schema (
archives.name UNIQUE), updates docs, and adds regression tests covering the reported scenarios.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| UnityDataTool.Tests/AnalyzeDuplicateNameTests.cs | Adds tests covering duplicate loose files, duplicate archive names, and duplicate inner CAB files across differently named bundles. |
| Documentation/command-analyze.md | Reframes the prior “SQL constraint errors” section into the new duplicate-name messages with guidance on single-build analysis. |
| Analyzer/SQLite/Writers/SerializedFileSQLiteWriter.cs | Tracks written archive names and SerializedFile ids and throws AnalyzeDuplicateException before hitting SQLite constraint failures. |
| Analyzer/SQLite/Parsers/SerializedFileParser.cs | Catches AnalyzeDuplicateException for duplicate inner SerializedFiles in archives and prints a clean skip message. |
| Analyzer/SQLite/Commands/SerializedFile/AddArchive.cs | Updates the documented table definition to match the schema’s uniqueness rule. |
| Analyzer/Resources/Init.sql | Makes archives.name unique and bumps schema user_version to 6, with updated commentary. |
| Analyzer/AnalyzerTool.cs | Catches AnalyzeDuplicateException at the top level and prints a clean one-line message while continuing and counting failure. |
| Analyzer/AnalyzeDuplicateException.cs | New exception type carrying duplicate name and archive-vs-SerializedFile context with a self-contained message. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
16
to
+20
| id INTEGER, | ||
| name TEXT, | ||
| file_size INTEGER, | ||
| PRIMARY KEY (id) | ||
| PRIMARY KEY (id), | ||
| UNIQUE (name) |
Comment on lines
8
to
14
| ( | ||
| id INTEGER, | ||
| name TEXT, | ||
| file_size INTEGER, | ||
| PRIMARY KEY (id) | ||
| PRIMARY KEY (id), | ||
| UNIQUE (name) | ||
| ); |
Comment on lines
+57
to
+59
| // Case 2 / Case 3: two build folders each contain an archive named "assetbundle" (and "scenes"). | ||
| // The second archive of each name is rejected before it is opened, so exactly one row per name | ||
| // survives and no UNIQUE constraint error is shown. |
…comments - Compare archive names case-sensitively so the code matches the case-sensitive archives.name UNIQUE constraint and the name as it exists on the file system (drops the OrdinalIgnoreCase set). - Fix the comparing-builds.md link to be same-folder relative. - Clarify the schema comment and a test comment.
Collaborator
Author
|
Addressed the Copilot review in 2e74649:
Full suite green (Analyzer 62, UnityFileSystem 425/10 skipped, UnityDataTool 259). |
SkowronskiAndrew
marked this pull request as ready for review
July 21, 2026 13:28
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
Fixes #51.
analyzeonly supports a single build at a time: Unity resolves references betweenSerializedFiles by file name, so two files sharing a name are indistinguishable to those
references. Previously, analyzing more than one copy of the same content produced a raw
SQLite Error 19: 'UNIQUE constraint failed: serialized_files.id'that was only visible with-v, and two archives sharing a name were silently recorded as two ambiguous rows.This detects those cases and reports a distinctive, self-contained one-line message, skips the
offending file/archive, and continues (counting it as a failed file). The archive-name invariant
is now also enforced at the schema level.
Changes
AnalyzeDuplicateExceptioncarrying the colliding name; its message leads with adistinctive phrase (
Duplicate SerializedFile name/Duplicate archive name) that isdocumented, so a user can find the explanation from the message text.
SerializedFileSQLiteWritertracks already-written SerializedFile ids and archive names andrejects a duplicate before the insert (no failed transaction, no reliance on parsing SQLite
error codes).
BeginArchiveassigns its id before the check so the caller'sEndArchive(in its
finally) unwinds cleanly rather than masking the exception.SerializedFileParserandAnalyzerToolcatch the new exception and print one clean line,always visible (not gated on
-v).archives.nameis nowUNIQUE;user_versionbumped 5 → 6.command-analyze.mdaround the newmessages (why only a single build can be analyzed; expected for AssetBundle variants; analyze
continues and ignores the duplicate).
Testing
dotnet test— full suite green (Analyzer.Tests 62, UnityFileSystem.Tests 425/10 skipped,UnityDataTool.Tests 259).
AnalyzeDuplicateNameTestscovers the three issue scenarios: loose files with the samename, archives with the same name, and differently-named archives (hashed bundle names) that
share the same inner SerializedFile.
clean single-line message with no raw SQLite error.