Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Commit

Permalink
Show errors and better cancellation messages in StatusPoller (mobile-…
Browse files Browse the repository at this point in the history
  • Loading branch information
axelniklasson authored Aug 31, 2023
1 parent 54742c3 commit 2bc194f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
13 changes: 11 additions & 2 deletions ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,18 @@ export class UploadStatusError {
constructor(public status: number, public text: string) { }
}

export enum CancellationReason {
BENCHMARK_DEPENDENCY_FAILED = 'BENCHMARK_DEPENDENCY_FAILED',
INFRA_ERROR = 'INFRA_ERROR',
OVERLAPPING_BENCHMARK = 'OVERLAPPING_BENCHMARK',
TIMEOUT = 'TIMEOUT',
}

export type Flow = {
name: string,
status: BenchmarkStatus
status: BenchmarkStatus,
errors?: string[],
cancellationReason?: CancellationReason
}

export type UploadStatusResponse = {
Expand Down Expand Up @@ -99,7 +108,7 @@ export default class ApiClient {
async getUploadStatus(
uploadId: string,
): Promise<UploadStatusResponse> {
const res = await fetch(`${this.apiUrl}/v2/upload/${uploadId}/status`, {
const res = await fetch(`${this.apiUrl}/v2/upload/${uploadId}/status?includeErrors=true`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${this.apiKey}`,
Expand Down
27 changes: 24 additions & 3 deletions StatusPoller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as core from '@actions/core'
import ApiClient, { BenchmarkStatus, Flow, UploadStatusError } from "./ApiClient";
import ApiClient, { BenchmarkStatus, CancellationReason, Flow, UploadStatusError } from "./ApiClient";
import { canceled, err, info, success, warning } from './log';

const WAIT_TIMEOUT_MS = 1000 * 60 * 30 // 30 minutes
Expand All @@ -8,15 +8,36 @@ const TERMINAL_STATUSES = new Set([BenchmarkStatus.SUCCESS, BenchmarkStatus.ERRO

const isCompleted = (flow: Flow): boolean => TERMINAL_STATUSES.has(flow.status)

const getCanceledStatusMessage = (reason?: CancellationReason): string => {
switch (reason) {
case CancellationReason.BENCHMARK_DEPENDENCY_FAILED:
case CancellationReason.OVERLAPPING_BENCHMARK:
return 'Skipped';

case CancellationReason.TIMEOUT:
return 'Timeout';

case CancellationReason.INFRA_ERROR:
default:
return 'Canceled';
}
}

const renderError = (errors?: string[]): string => {
if (!errors || errors.length === 0) return '';

return ` (${errors[0]})`;
}

const printFlowResult = (flow: Flow): void => {
if (flow.status === BenchmarkStatus.SUCCESS) {
success(`[Passed] ${flow.name}`)
} else if (flow.status === BenchmarkStatus.ERROR) {
err(`[Failed] ${flow.name}`)
err(`[Failed] ${flow.name}${renderError(flow.errors)}`)
} else if (flow.status === BenchmarkStatus.WARNING) {
warning(`[Warning] ${flow.name}`)
} else if (flow.status === BenchmarkStatus.CANCELED) {
canceled(`[Canceled] ${flow.name}`)
canceled(`[${getCanceledStatusMessage(flow.cancellationReason)}] ${flow.name}`)
}
}

Expand Down

0 comments on commit 2bc194f

Please sign in to comment.