fix: skip unknown chunk types instead of aborting the whole read - #32
Merged
Conversation
readChunk() threw on any chunk type it didn't recognize. A future PCM version adding a new chunk type to the save format would make this library unable to read those saves at all, even for tables/chunks it otherwise understands. Since every chunk header carries its own chunkSize, an unknown chunk can be skipped by byte count (with a warning) instead of aborting, preserving forward compatibility. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR improves forward compatibility in the CDB binary reader by no longer aborting parsing when it encounters an unknown chunk type, allowing newer game versions to introduce additional chunks without breaking table/data extraction.
Changes:
- Replace the hard error on unknown chunk types with logic that skips over the chunk using the declared
chunkSize. - Emit a warning when an unknown chunk is encountered (currently via
console.warn).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
src/reader.ts:256
- The unknown-chunk path logs "Skipping..." before validating the declared chunk size, which can produce a misleading warning immediately before throwing. Also, checking
typeof console !== "undefined"doesn’t guaranteeconsole.warnexists.
if (typeof console !== "undefined") {
console.warn(
`Skipping unknown chunk type: 0x${(header.chunkType as number).toString(16)} at position ${chunkStartPos}`,
);
}
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/reader.ts:256
console.warn(...)is called unconditionally onceconsoleexists. In some JS runtimesconsolemay exist butconsole.warnmay be missing/non-function (or stubbed), which would throw while trying to recover from an unknown chunk. Consider using a safe optional invocation viaglobalThis.console?.warn?.(...)so skipping remains non-fatal across environments.
if (typeof console !== "undefined") {
console.warn(
`Skipping unknown chunk type: 0x${(header.chunkType as number).toString(16)} at position ${chunkStartPos}`,
);
}
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
readChunk()threw immediately on any chunk type it didn't recognize, which would make the library entirely unable to parse a save file the moment a future game version introduces a new chunk type — even if that chunk is unrelated to the tables/data actually being read.chunkSize, an unknown chunk can now be skipped by byte count (logging aconsole.warn) instead of aborting the whole parse.