Skip to content

fix(session): include root cause for invalid project, region, or session template - #229

Merged
dborowitz merged 1 commit into
mainfrom
dborowitz-create-session-errors
Nov 4, 2026
Merged

dborowitz merged 1 commit into
mainfrom
dborowitz-create-session-errors

Conversation

@dborowitz

@dborowitz dborowitz commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

When create_session fails due to a typo in the project ID, region, or session template, surface the underlying error details instead of raising an opaque HTTP 404 or dropping structured gRPC metadata:

  • Catch MethodNotImplemented alongside InvalidArgument and PermissionDenied, and translate HTTP 404 responses from the regional endpoint ({region}-dataproc.googleapis.com) into an actionable message prompting the user to check that the location is a valid Managed Spark region.
  • Surface structured DebugInfo details, ErrorInfo reasons (CONSUMER_INVALID, RESOURCE_PROJECT_INVALID, LOCATION_POLICY_VIOLATED), and BadRequest field violations when formatting session creation errors, plus a format hint when a malformed session_template reference fails with a generic InvalidArgument.
  • Chain the original exception with from e on ManagedSparkConnectException so full tracebacks preserve the underlying gRPC error, and pin ImportError.msg on PySparkNotInstalledError in unit tests.
  • Add unit and integration tests covering invalid project IDs, invalid regions, and nonexistent or malformed session templates.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves error handling and reporting when creating a Managed Spark Session. Key changes include changing ManagedSparkConnectException to inherit from RuntimeError, adding detailed error extraction and formatting logic for API errors (such as invalid project IDs, invalid regions, and malformed session templates), and introducing a helper function to clean up failed session creations. Additionally, comprehensive integration and unit tests have been added to verify these error handling paths. There are no review comments to address, and I have no further feedback to provide.

@dborowitz
dborowitz requested a review from tim-u November 3, 2026 02:17
@dborowitz
dborowitz force-pushed the dborowitz-create-session-errors branch from 1b2d66b to 4492068 Compare November 3, 2026 02:43

@tim-u tim-u left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, but it'll be permanent in history: the commit message has a local path pasted into the endpoint pattern. It reads "(<region> /usr/local/google/home/dborowitz/.gemini/config/-dataproc.googleapis.com)"; it should read <region>-dataproc.googleapis.com. Probably worth fixing before merge, since it also leaks a username/home dir.

@dborowitz
dborowitz force-pushed the dborowitz-create-session-errors branch from 4492068 to 40fa8a0 Compare November 3, 2026 22:44
@dborowitz

Copy link
Copy Markdown
Contributor Author

Good catch on both points:

  1. Reverted ManagedSparkConnectException back to inheriting from Exception so PySparkNotInstalledError(ManagedSparkConnectException, ImportError) keeps ImportError.__init__ in its MRO (e.msg is populated and it isn't a RuntimeError), and pinned e.msg and not isinstance(e, RuntimeError) in TestWithoutPySpark.
  2. Fixed the mangled {region}-dataproc.googleapis.com text in the commit message.

…ion template

When create_session fails due to a typo in the project ID, region, or
session template, explain the underlying failure instead of raising an
opaque HTTP 404 or swallowing structured error details:

- Catch MethodNotImplemented alongside InvalidArgument and
  PermissionDenied, and translate HTTP 404 responses from the regional
  endpoint ({region}-dataproc.googleapis.com) into an actionable message
  telling the user to verify that the location is a valid Managed Spark
  region.
- Surface structured DebugInfo details, ErrorInfo reasons
  (CONSUMER_INVALID, RESOURCE_PROJECT_INVALID, LOCATION_POLICY_VIOLATED),
  and BadRequest field violations when formatting session creation
  errors, plus a format hint when a malformed session_template reference
  fails with a generic InvalidArgument.
- Chain the original exception with 'from e' on
  ManagedSparkConnectException so full tracebacks preserve the
  underlying gRPC error, and pin ImportError.msg on
  PySparkNotInstalledError in unit tests.
- Add unit and integration tests covering invalid project IDs, invalid
  regions, and nonexistent or malformed session templates.
@dborowitz
dborowitz force-pushed the dborowitz-create-session-errors branch from 40fa8a0 to 62c3284 Compare November 3, 2026 23:01
@dborowitz
dborowitz merged commit 10cc871 into main Nov 4, 2026
36 of 37 checks passed
@dborowitz
dborowitz deleted the dborowitz-create-session-errors branch November 4, 2026 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants