Skip to content

Commit

Permalink
Improve zip error messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
jmccollum-woolpert committed Feb 7, 2024
1 parent f6734fa commit 02485dd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ <h4 class="strong d-flex mb-2">
*ngIf="
fileName.errors?.required && fileName.touched && fileName.dirty && !validatingUpload
">
File is required
File is required.
</mat-error>
<mat-error *ngIf="fileName.errors?.zipContents && (fileName.touched || fileName.dirty)">
Invalid zip contents
{{ getZipErrorMessage() }}
</mat-error>
<mat-error *ngIf="fileName.errors?.fileFormat && (fileName.touched || fileName.dirty)">
Invalid file format
The provided file cannot be loaded. Only valid .json and .zip files are supported.
</mat-error>
<mat-error *ngIf="fileName.errors?.requestFormat && (fileName.touched || fileName.dirty)">
The provided scenario is not valid
The provided scenario is not valid.
</mat-error>
<mat-hint>.json or .zip</mat-hint>
</mat-form-field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export class UploadDialogComponent {
}
private scenarioSolutionPair: ScenarioSolutionPair;
zipContentsInvalid: boolean;
zipContentCountInvalid: boolean;
zipMissingScenario: boolean;
zipMissingSolution: boolean;

resolvingPlaceIds = false;
placeIdProgress = 0;
Expand Down Expand Up @@ -300,7 +303,12 @@ export class UploadDialogComponent {
}

loadZipContents(files: { content: JSON; filename: string }[]): ScenarioSolutionPair {
this.zipContentCountInvalid = false;
this.zipMissingScenario = false;
this.zipMissingSolution = false;

if (files.length !== 2) {
this.zipContentCountInvalid = true;
throw new Error('Incorrect number of files');
}

Expand All @@ -316,16 +324,33 @@ export class UploadDialogComponent {
});

if (!scenario) {
this.zipMissingScenario = true;
throw new Error('Missing scenario.json');
}

if (!solution) {
this.zipMissingSolution = true;
throw new Error('Missing solution.json');
}

return { scenario, solution };
}

getZipErrorMessage(): string {
if (this.zipContentCountInvalid) {
return 'The zip contains an invalid number of .json files, or the .json files within are invalid.';
}
if (this.zipMissingScenario) {
return 'The provided zip is missing a valid scenario file.';
}

if (this.zipMissingSolution) {
return 'The provided zip is missing a valid solution file.';
}

return 'The provided zip contains invalid contents.';
}

/**
* Returns scenario validation errors
*
Expand Down

0 comments on commit 02485dd

Please sign in to comment.