Skip to content

Commit

Permalink
Merge pull request #1747 from jplag/report-viewer/better-warning
Browse files Browse the repository at this point in the history
Better warning for missing files
  • Loading branch information
tsaglam authored May 14, 2024
2 parents 742b46e + 7edcd56 commit e91e4bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
26 changes: 19 additions & 7 deletions report-viewer/src/model/factories/ComparisonFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ export class ComparisonFactory extends BaseFactory {

const matches = json.matches as Array<Record<string, unknown>>
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))
Expand Down Expand Up @@ -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<string, unknown>): Match {
Expand Down
4 changes: 2 additions & 2 deletions report-viewer/src/stores/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e91e4bc

Please sign in to comment.