Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error messages (duplicate artifacts; too many artifacts) #1600

Merged
merged 10 commits into from
Dec 11, 2023
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/artifact/src/internal/shared/artifact-twirp-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class ArtifactHttpClient implements Rpc {
let errorMessage = ''
while (attempt < this.maxAttempts) {
let isRetryable = false
let isDuplicateArtifactName = false
let isTooManyArtifacts = false
vmjoseph marked this conversation as resolved.
Show resolved Hide resolved
const maxArtifacts = 10

try {
const response = await operation()
Expand All @@ -89,13 +92,23 @@ class ArtifactHttpClient implements Rpc {
return {response, body}
}

isDuplicateArtifactName = this.isAlreadyExistsStatusCode(statusCode)
isTooManyArtifacts = this.isTooManyArtifacts(statusCode)
isRetryable = this.isRetryableHttpStatusCode(statusCode)
errorMessage = `Failed request: (${statusCode}) ${response.message.statusMessage}`
} catch (error) {
isRetryable = true
errorMessage = error.message
}

if (isDuplicateArtifactName) {
throw new Error(`Artifact name already exists`)
}
if (isTooManyArtifacts) {
throw new Error(
`Reached artifact upload limit for job; limit is ${maxArtifacts}`
)
}
if (!isRetryable) {
throw new Error(`Received non-retryable error: ${errorMessage}`)
}
Expand All @@ -120,6 +133,16 @@ class ArtifactHttpClient implements Rpc {
throw new Error(`Request failed`)
}

isAlreadyExistsStatusCode(statusCode?: number): boolean {
if (!statusCode) return false
return statusCode === HttpCodes.Conflict
}

isTooManyArtifacts(statusCode?: number): boolean {
if (!statusCode) return false
return statusCode === HttpCodes.BadRequest
}

isSuccessStatusCode(statusCode?: number): boolean {
if (!statusCode) return false
return statusCode >= 200 && statusCode < 300
Expand Down
Loading