Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: catch CMPro DAT parsing errors #782

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/@types/robloachDatfile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ interface DatfileHeader {

interface DatfileGame {
name: string,
entries: DatfileEntry[],
description: string,
entries?: DatfileEntry[],
description?: string,
}

interface DatfileEntry {
Expand Down
15 changes: 13 additions & 2 deletions src/modules/datScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ export default class DATScanner extends Scanner {
}

private async downloadDats(datFiles: File[]): Promise<File[]> {
if (!datFiles.some((datFile) => datFile.isURL())) {
return datFiles;
}

this.progressBar.logDebug('downloading DATs from URLs');
await this.progressBar.setSymbol(ProgressBarSymbol.DOWNLOADING);

return (await Promise.all(datFiles.map(async (datFile) => {
if (!datFile.isURL()) {
Expand Down Expand Up @@ -104,7 +109,12 @@ export default class DATScanner extends Scanner {
const waitingMessage = `${datFile.toString()} ...`;
this.progressBar.addWaitingMessage(waitingMessage);

const dat = await this.parseDatFile(datFile);
let dat: DAT | undefined;
try {
dat = await this.parseDatFile(datFile);
} catch (error) {
this.progressBar.logWarn(`${datFile.toString()}: failed to parse DAT file: ${error}`);
}

await this.progressBar.incrementDone();
this.progressBar.removeWaitingMessage(waitingMessage);
Expand Down Expand Up @@ -305,7 +315,8 @@ export default class DATScanner extends Scanner {
const cmproGames = cmproDat.slice(1);
const games = cmproGames.flatMap((obj) => {
const game = obj as DatfileGame;
const roms = game.entries
// TODO(cemmer): https://github.com/RobLoach/datfile/issues/2
const roms = (game.entries ?? [])
.filter((rom) => rom.name) // we need ROM filenames
.map((entry) => new ROM({
name: entry.name ?? '',
Expand Down
Loading