Skip to content

Commit 90073ff

Browse files
authored
Merge pull request #3337 from OpenNeuroOrg/hotfix/validation-resolver-crash
fix(api): Prevent crash on no validation results for reference
2 parents 70aec54 + 0808fb5 commit 90073ff

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

packages/openneuro-server/src/graphql/resolvers/validation.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ export const validation = async (dataset, _, { userInfo }) => {
2222
{ userInfo },
2323
)
2424
}
25-
// Return with errors and warning counts appended
26-
return {
27-
...data.toObject(),
28-
errors: data.issues.filter((issue) =>
29-
issue.severity === "error"
30-
).length,
31-
warnings:
32-
data.issues.filter((issue) => issue.severity === "warning").length,
25+
if (data) {
26+
// Return with errors and warning counts appended
27+
return {
28+
...data.toObject(),
29+
errors: data.issues.filter((issue) =>
30+
issue.severity === "error"
31+
).length,
32+
warnings: data.issues.filter((issue) =>
33+
issue.severity === "warning"
34+
).length,
35+
}
36+
} else {
37+
return null
3338
}
3439
})
3540
}
@@ -43,13 +48,19 @@ export const snapshotValidation = async (snapshot) => {
4348
id: snapshot.hexsha,
4449
datasetId,
4550
}).exec()
46-
// Return with errors and warning counts appended
47-
return {
48-
...validation.toObject(),
49-
errors:
50-
validation.issues.filter((issue) => issue.severity === "error").length,
51-
warnings:
52-
validation.issues.filter((issue) => issue.severity === "warning").length,
51+
if (validation) {
52+
// Return with errors and warning counts appended
53+
return {
54+
...validation.toObject(),
55+
errors: validation.issues.filter((issue) =>
56+
issue.severity === "error"
57+
).length,
58+
warnings:
59+
validation.issues.filter((issue) => issue.severity === "warning")
60+
.length,
61+
}
62+
} else {
63+
return null
5364
}
5465
}
5566

0 commit comments

Comments
 (0)