Skip to content

Commit

Permalink
fix error messages while gcs upload
Browse files Browse the repository at this point in the history
  • Loading branch information
itsankit-google committed Feb 4, 2025
1 parent 33bdca1 commit 3f10621
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,19 @@ public Optional<RuntimeJobDetail> getDetail(ProgramRunInfo programRunInfo) throw
getJobStatusDetails(job)));
} catch (ApiException e) {
if (e.getStatusCode().getCode() != StatusCode.Code.NOT_FOUND) {
throw new Exception(String.format("Error while getting details for job %s on cluster %s.",
jobId, clusterName), e);
int code = e.getStatusCode().getCode().getHttpStatusCode();
ActionErrorPair pair = ErrorUtils.getActionErrorByStatusCode(code);
throw new ProgramFailureException.Builder()
.withErrorCategory(new ErrorCategory(ErrorCategoryEnum.OTHERS))
.withErrorReason(String.format("%s Unable to get details for job %s on cluster %s. %s",
code, jobId, clusterName, pair.getCorrectiveAction()))
.withErrorMessage(e.getMessage())
.withErrorType(pair.getErrorType())
.withDependency(true)
.withErrorCodeType(ErrorCodeType.HTTP)
.withErrorCode(String.valueOf(code))
.withCause(e)
.build();
}
// Status is not found if job is finished or manually deleted by the user
LOG.debug("Dataproc job {} does not exist in project {}, region {}.", jobId, projectId,
Expand Down Expand Up @@ -560,7 +571,13 @@ private LocalFile uploadCacheableFile(String bucket, String targetFilePath,
Storage.BlobWriteOption.metagenerationMatch());
} catch (StorageException e) {
if (e.getCode() != HttpURLConnection.HTTP_PRECON_FAILED) {
throw e;
ActionErrorPair pair = ErrorUtils.getActionErrorByStatusCode(e.getCode());
String errorReason = String.format("%s Unable to upload file %s to GCS bucket gs://%s."
+ " %s", e.getCode(), localFile.getURI(), bucket, pair.getCorrectiveAction());
throw ErrorUtils.getProgramFailureException(
new ErrorCategory(ErrorCategoryEnum.STARTING), errorReason, e.getMessage(),
pair.getErrorType(), true, ErrorCodeType.HTTP, String.valueOf(e.getCode()),
GCS_DOC_URL, e);
}
// Precondition failed means file has already been replaced, hence ignore it.
LOG.debug("Skip uploading file {} to gs://{}/{} because it exists.",
Expand Down Expand Up @@ -633,8 +650,8 @@ public LocalFile uploadFile(String bucket, String targetFilePath,
} catch (StorageException e) {
if (e.getCode() != HttpURLConnection.HTTP_PRECON_FAILED) {
ActionErrorPair pair = ErrorUtils.getActionErrorByStatusCode(e.getCode());
String errorReason = String.format("%s Unable to access GCS bucket %s. %s", e.getCode(),
bucket, pair.getCorrectiveAction());
String errorReason = String.format("%s Unable to upload file %s to GCS bucket gs://%s. %s",
e.getCode(), localFile.getURI(), bucket, pair.getCorrectiveAction());
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategoryEnum.STARTING),
errorReason, e.getMessage(), pair.getErrorType(), true,
ErrorCodeType.HTTP, String.valueOf(e.getCode()), GCS_DOC_URL, e);
Expand Down

0 comments on commit 3f10621

Please sign in to comment.