Skip to content

Commit

Permalink
Catch CMPro DAT parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm committed Oct 22, 2023
1 parent af710cc commit 2a75534
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
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

0 comments on commit 2a75534

Please sign in to comment.