Skip to content

Commit

Permalink
Better handling of crash report without test failure
Browse files Browse the repository at this point in the history
Return a 400 response with a useful error message.

Part of #73.
  • Loading branch information
lawrence-forooghian committed May 3, 2023
1 parent 37c28e8 commit 73314d9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
53 changes: 33 additions & 20 deletions src/uploads/postUploads.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {
ValidateNested,
} from 'class-validator';
import { Type } from 'class-transformer';
import { UploadCreationCrashReport, UploadsService } from './uploads.service';
import {
CrashReportWithoutFailureError,
UploadCreationCrashReport,
UploadsService,
} from './uploads.service';
import { Upload } from './upload.entity';

Check warning on line 22 in src/uploads/postUploads.controller.ts

View workflow job for this annotation

GitHub Actions / lint

'Upload' is defined but never used

class CreateUploadDTO {
@IsString()
Expand Down Expand Up @@ -122,24 +127,32 @@ export class PostUploadsController {
}));
}

const upload = await this.uploadsService.create(
{
junitReportXml,
githubRepository: body.github_repository,
githubSha: body.github_sha,
githubRefName: body.github_ref_name,
githubRetentionDays: body.github_retention_days,
githubAction: body.github_action,
githubRunNumber: body.github_run_number,
githubRunAttempt: body.github_run_attempt,
githubRunId: body.github_run_id,
githubBaseRef: body.github_base_ref,
githubHeadRef: body.github_head_ref,
githubJob: body.github_job,
iteration: body.iteration,
},
crashReports,
);
return { id: upload.id };
try {
const upload = await this.uploadsService.create(
{
junitReportXml,
githubRepository: body.github_repository,
githubSha: body.github_sha,
githubRefName: body.github_ref_name,
githubRetentionDays: body.github_retention_days,
githubAction: body.github_action,
githubRunNumber: body.github_run_number,
githubRunAttempt: body.github_run_attempt,
githubRunId: body.github_run_id,
githubBaseRef: body.github_base_ref,
githubHeadRef: body.github_head_ref,
githubJob: body.github_job,
iteration: body.iteration,
},
crashReports,
);

return { id: upload.id };
} catch (err) {
if (err instanceof CrashReportWithoutFailureError) {
throw new HttpException(err.message, HttpStatus.BAD_REQUEST);
}
throw err;
}
}
}
6 changes: 4 additions & 2 deletions src/uploads/uploads.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface UploadCreationCrashReport {
data: Buffer;
}

export class CrashReportWithoutFailureError extends Error {}

@Injectable()
export class UploadsService {
constructor(
Expand Down Expand Up @@ -126,8 +128,8 @@ export class UploadsService {
);

if (!failure) {
throw new Error(
`No failure found with testClassName ${uploadCreationCrashReport.testClassName} and testCaseName ${uploadCreationCrashReport.testCaseName}`,
throw new CrashReportWithoutFailureError(
`There is no test failure corresponding to the crash report with testClassName ${uploadCreationCrashReport.testClassName} and testCaseName ${uploadCreationCrashReport.testCaseName}`,
);
}

Expand Down

0 comments on commit 73314d9

Please sign in to comment.