diff --git a/report-viewer/src/model/factories/ComparisonFactory.ts b/report-viewer/src/model/factories/ComparisonFactory.ts index f66df2797..4e2b07e0b 100644 --- a/report-viewer/src/model/factories/ComparisonFactory.ts +++ b/report-viewer/src/model/factories/ComparisonFactory.ts @@ -32,14 +32,20 @@ export class ComparisonFactory extends BaseFactory { const matches = json.matches as Array> matches.forEach((match) => { - store().getSubmissionFile( - firstSubmissionId, - slash(match.file1 as string) - ).matchedTokenCount += match.tokens as number - store().getSubmissionFile( + const fileOfFirst = store().getSubmissionFile(firstSubmissionId, slash(match.file1 as string)) + const fileOfSecond = store().getSubmissionFile( secondSubmissionId, slash(match.file2 as string) - ).matchedTokenCount += match.tokens as number + ) + + if (fileOfFirst == undefined || fileOfSecond == undefined) { + throw new Error( + `The report viewer expected to find the file ${fileOfFirst == undefined ? match.file1 : match.file2} in the submissions, but did not find it.` + ) + } + + fileOfFirst.matchedTokenCount += match.tokens as number + fileOfSecond.matchedTokenCount += match.tokens as number }) const unColoredMatches = matches.map((match) => this.getMatch(match)) @@ -115,7 +121,13 @@ export class ComparisonFactory extends BaseFactory { if (store().state.localModeUsed && !store().state.zipModeUsed) { return await this.getLocalFile('files/' + fileName).then((file) => file.text()) } - return store().getSubmissionFile(submissionId, fileName).data + const file = store().getSubmissionFile(submissionId, fileName) + if (file == undefined) { + throw new Error( + `The report viewer expected to find the file ${fileName} in the submissions, but did not find it.` + ) + } + return file.data } private static getMatch(match: Record): Match { diff --git a/report-viewer/src/stores/store.ts b/report-viewer/src/stores/store.ts index 9829d33d4..9943e4ec2 100644 --- a/report-viewer/src/stores/store.ts +++ b/report-viewer/src/stores/store.ts @@ -49,8 +49,8 @@ const store = defineStore('store', { */ getSubmissionFile: (state) => - (submissionId: string, fileName: string): SubmissionFile => { - return state.state.submissions[submissionId].get(fileName) as SubmissionFile + (submissionId: string, fileName: string): SubmissionFile | undefined => { + return state.state.submissions[submissionId].get(fileName) }, /** * @param name the name of the submission