fix: Ensure DataprocSparkConnectException displays error messages in all Jupyter environments - #138
Conversation
…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
There was a problem hiding this comment.
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
DataprocSparkConnectExceptionerrors 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 theDataprocSparkConnectExceptionclass. This method overrides IPython's defaultshowtracebackbehavior specifically for instances ofDataprocSparkConnectException. - 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
-
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. ↩
There was a problem hiding this comment.
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.
- 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
- 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
dborowitz
left a comment
There was a problem hiding this comment.
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.
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
- 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

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:
Root Cause
GCP Workbench's Jupyter implementation doesn't consistently call the render_traceback() method.
Solution
Test plan