Skip to content

fix: skip unknown chunk types instead of aborting the whole read - #32

Merged
mpicciolli merged 7 commits into
mainfrom
fix/skip-unknown-chunk-types
Jul 21, 2026
Merged

fix: skip unknown chunk types instead of aborting the whole read#32
mpicciolli merged 7 commits into
mainfrom
fix/skip-unknown-chunk-types

Conversation

@mpicciolli

@mpicciolli mpicciolli commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

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.
  • Since every chunk header already carries its own chunkSize, an unknown chunk can now be skipped by byte count (logging a console.warn) instead of aborting the whole parse.
  • Given the project already supports save formats spanning 2014–2025, forward compatibility with future chunk types seems like a reasonable goal.

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>
Copilot AI review requested due to automatic review settings July 15, 2026 14:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src/reader.ts Outdated
Comment thread src/reader.ts
Comment thread src/reader.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 guarantee console.warn exists.
					if (typeof console !== "undefined") {
						console.warn(
							`Skipping unknown chunk type: 0x${(header.chunkType as number).toString(16)} at position ${chunkStartPos}`,
						);
					}

Comment thread test/reader.test.ts
Comment thread test/reader.test.ts
mpicciolli and others added 2 commits July 20, 2026 21:56
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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 once console exists. In some JS runtimes console may exist but console.warn may be missing/non-function (or stubbed), which would throw while trying to recover from an unknown chunk. Consider using a safe optional invocation via globalThis.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}`,
						);
					}

@mpicciolli
mpicciolli merged commit 6b531d3 into main Jul 21, 2026
10 checks passed
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.

2 participants