Skip to content

fix: Ensure DataprocSparkConnectException displays error messages in all Jupyter environments - #138

Merged
medb merged 7 commits into
GoogleCloudDataproc:branch-0.xfrom
fangyh20:exception
Sep 24, 2025
Merged

medb merged 7 commits into
GoogleCloudDataproc:branch-0.xfrom
fangyh20:exception

Conversation

@fangyh20

Copy link
Copy Markdown
Member

Summary

Fix silent exception behavior in GCP Workbench where DataprocSparkConnectException error messages weren't displayed without try-catch blocks.

Problem

When using default network to create sessions, error messages like 'Subnetwork default does not exist' were:

  • Displayed correctly in Google Colab
  • Silent in GCP Workbench (Jupyter) without try-catch blocks
  • Displayed when wrapped with try-catch

Root Cause

GCP Workbench's Jupyter implementation doesn't consistently call the render_traceback() method.

Solution

  • Added _setup_ipython_exception_handler() that overrides IPython's showtraceback method
  • Shows minimal error messages consistently across all Jupyter environments
  • Maintains backward compatibility with existing Colab behavior

Test plan

  • Test error display in both Colab and GCP Workbench environments
  • Verify non-IPython environments continue working normally

…all Jupyter environments

- Fix silent exception behavior in GCP Workbench where error messages weren't displayed
- Add cross-environment IPython exception handler for consistent minimal traceback display
- Maintain backward compatibility with Colab's _render_traceback_() method
- Remove redundant __str__() method relying on base Exception class

@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.

Summary of Changes

Hello @fangyh20, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical issue where DataprocSparkConnectException errors were silently suppressed in GCP Workbench's Jupyter environment, hindering debugging efforts. By implementing a custom IPython exception handler, the change guarantees that relevant error messages are consistently displayed to the user, significantly improving the developer experience when encountering connection-related issues.

Highlights

  • Problem Addressed: Fixed silent DataprocSparkConnectException errors that were occurring in GCP Workbench Jupyter environments, where error messages were not displayed without explicit try-catch blocks.
  • Root Cause Identified: The issue stemmed from GCP Workbench's Jupyter implementation not consistently calling the _render_traceback_ method for exceptions.
  • Solution Implemented: Introduced a new private method, _setup_ipython_exception_handler(), within the DataprocSparkConnectException class. This method overrides IPython's default showtraceback behavior specifically for instances of DataprocSparkConnectException.
  • Impact: Ensures consistent display of minimal error messages across all Jupyter environments (including Google Colab and GCP Workbench) and maintains backward compatibility with existing Colab behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@fangyh20
fangyh20 requested a review from medb September 15, 2025 18:55

@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 addresses an important issue where exceptions were being silenced in certain Jupyter environments. The approach of patching IPython's showtraceback is a good solution.

My review includes a couple of important points:

  • A critical fix for the custom traceback handler's signature, which would otherwise cause a TypeError.
  • A high-severity recommendation to avoid re-patching the handler on every exception instantiation for efficiency.

I've provided code suggestions for both issues. Once these are addressed, the solution should be robust and effective.

Comment thread google/cloud/dataproc_spark_connect/exceptions.py Outdated
Comment thread google/cloud/dataproc_spark_connect/exceptions.py Outdated
@fangyh20

Copy link
Copy Markdown
Member Author
image

- Fix function signature for custom_showtraceback to include shell parameter
- Add class-level flag to prevent redundant IPython handler setup
- Improve efficiency by setting up exception handler only once per session
Comment thread google/cloud/dataproc_spark_connect/exceptions.py Outdated
Comment thread google/cloud/dataproc_spark_connect/exceptions.py Outdated
Comment thread google/cloud/dataproc_spark_connect/exceptions.py Outdated
Comment thread google/cloud/dataproc_spark_connect/exceptions.py Outdated
Comment thread google/cloud/dataproc_spark_connect/exceptions.py
- Move IPython exception handler setup to module level for efficiency
- Move sys import to top level as suggested
- Reduce try/except nesting depth by wrapping only IPython import
- Remove class-level flag and instance-level setup logic
- Handler now runs once at module import time instead of per exception
@fangyh20
fangyh20 requested a review from dborowitz September 16, 2025 22:32

@dborowitz dborowitz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks, this is easier to read with less nesting. What it's doing now is clear; I don't know enough about the ipython traceback system to know whether it's actually solving the problem, but I trust your testing.

Comment thread google/cloud/dataproc_spark_connect/exceptions.py Outdated

@medb medb 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.

Is this a duplicate of #136?

Comment thread google/cloud/dataproc_spark_connect/exceptions.py
Comment thread google/cloud/dataproc_spark_connect/exceptions.py
@fangyh20

Copy link
Copy Markdown
Member Author

Is this a duplicate of #136?

this is for merging to branch-0.x

…espace pollution

- Address dborowitz feedback to keep get_ipython import local
- Move IPython import inside _setup_ipython_exception_handler function
- Maintains same functionality with cleaner module namespace
@fangyh20
fangyh20 requested review from dborowitz and medb September 23, 2025 07:20
Comment thread google/cloud/dataproc_spark_connect/exceptions.py Outdated
Comment thread google/cloud/dataproc_spark_connect/exceptions.py
- Change _original_showtraceback to _dataproc_spark_connect_original_showtraceback
- Prevents potential conflicts with other libraries patching IPython
- Addresses feedback from medb to use more specific attribute names
@fangyh20
fangyh20 requested a review from medb September 24, 2025 01:01
@medb
medb merged commit c89c5b8 into GoogleCloudDataproc:branch-0.x Sep 24, 2025
1 check passed
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.

3 participants