Skip to content

Commit

Permalink
feat: reraise exceptions from API calls
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 494773031
  • Loading branch information
dizcology authored and Copybara-Service committed Dec 12, 2022
1 parent bc9e2cf commit d72bc83
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion google/cloud/aiplatform/datasets/column_names_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def _retrieve_gcs_source_columns(
"There was a problem extracting the headers from the CSV file at '{}': {}".format(
gcs_csv_file_path, err
)
)
) from err
finally:
logger.removeFilter(logging_warning_filter)

Expand Down
4 changes: 2 additions & 2 deletions google/cloud/aiplatform/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def project(self) -> str:

try:
_, project_id = google.auth.default()
except GoogleAuthError:
raise GoogleAuthError(project_not_found_exception_str)
except GoogleAuthError as exc:
raise GoogleAuthError(project_not_found_exception_str) from exc

if not project_id:
raise ValueError(project_not_found_exception_str)
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/aiplatform/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2508,10 +2508,10 @@ def training_job(self) -> Optional["aiplatform.training_jobs._TrainingJob"]:
location=self.location,
credentials=self.credentials,
)
except api_exceptions.NotFound:
except api_exceptions.NotFound as exc:
raise api_exceptions.NotFound(
f"The training job used to create this model could not be found: {job_name}"
)
) from exc

@property
def container_spec(self) -> Optional[model_v1.ModelContainerSpec]:
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/aiplatform/tensorboard/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ def flush(self):
hasattr(e, "code")
and getattr(e, "code")() == grpc.StatusCode.NOT_FOUND
):
raise ExperimentNotFoundError()
raise ExperimentNotFoundError() from e
logger.error("Upload call failed with error %s", e)

self._new_request()
Expand Down Expand Up @@ -1161,7 +1161,7 @@ def _validate(
"a bug in the process that wrote the tensor.\n\n"
"The tensor has tag '%s' and is at step %d and wall_time %.6f.\n\n"
"Original error:\n%s" % (value.tag, event.step, event.wall_time, error)
)
) from error
return True


Expand Down
2 changes: 1 addition & 1 deletion google/cloud/aiplatform/tensorboard/uploader_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def main(argv):
raise app.UsageError(
"Tensorboard resource %s not found" % FLAGS.tensorboard_resource_name,
exitcode=0,
)
) from rpc_error
raise

if tensorboard.blob_storage_path_prefix:
Expand Down

0 comments on commit d72bc83

Please sign in to comment.