diff --git a/src/JsonValidator/MultiscaleArrays/Multiscale.svelte b/src/JsonValidator/MultiscaleArrays/Multiscale.svelte index 8cfd673..ef91f18 100644 --- a/src/JsonValidator/MultiscaleArrays/Multiscale.svelte +++ b/src/JsonValidator/MultiscaleArrays/Multiscale.svelte @@ -5,19 +5,25 @@ export let source; export let multiscale; + const WARNING = "warning"; + // We check that all multiscale Datasets have same dtype and // shape.length (number of dimensions) // If multiscale.axes (version > 0.3) check it matches shape const {axes, datasets, version} = multiscale; - const checkDtypes = !["0.1", "0.2", "0.3", "0.4"].includes(version); + const permitDtypeMismatch = ["0.1", "0.2", "0.3", "0.4"].includes(version); const checkDimSeparator = ["0.2", "0.3", "0.4"].includes(version); function allEqual(items) { return items.every((value) => value == items[0]); } + function containsError(checks) { + return checks.some(check => check.status != WARNING); + } + async function loadAndValidate() { let dtypes = []; let dimCounts = []; @@ -33,32 +39,37 @@ dimSeparators.push(zarray.dimension_separator); } - let errors = []; + // Each check is {msg: "Message"}, with status: "warning" if it isn't an Error. + let checks = []; if (dtypes.length === 0) { - errors.push("No multiscale datasets") + checks.push({msg: "No multiscale datasets"}) } - if (checkDtypes && !allEqual(dtypes)) { - errors.push(`dtypes mismatch: ${dtypes.join(", ")}`) + if (!allEqual(dtypes)) { + if (permitDtypeMismatch) { + checks.push({msg: `dtypes mismatch: ${dtypes.join(", ")}`, status: WARNING}) + } else { + checks.push({msg: `dtypes mismatch: ${dtypes.join(", ")}`}) + } } if (!allEqual(dimCounts)) { - errors.push(`number of dimensions mismatch: ${dimCounts.join(", ")}`) + checks.push({msg: `number of dimensions mismatch: ${dimCounts.join(", ")}`}) } if (axes) { shapes.forEach((shape) => { if (shape.length != axes.length) { - errors.push(`Shape (${shape.join(", ")}) doesn't match axes length: ${axes.length}`) + checks.push({msg: `Shape (${shape.join(", ")}) doesn't match axes length: ${axes.length}`}) } }); } if (checkDimSeparator) { dimSeparators.forEach((sep) => { if (sep != "/") { - errors.push(`Dimension separator must be / for version ${version}`) + checks.push({msg: `Dimension separator must be / for version ${version}`}) } }); } - return errors; + return checks; } const promise = loadAndValidate(); @@ -66,18 +77,22 @@ {#await promise}
loading...
-{:then errors} - {#if errors.length > 0} +{:then checks} + {#if containsError(checks)}Error: {error}
- {/each} {:else}{datasets.length} Datasets checked ✓
{/if} + {#each checks as check} + {#if check.status == "warning"} +Warning: {check.msg}
+ {:else} +Error: {check.msg}
+ {/if} + {/each} {:catch error}{error.message}
{/await}