Skip to content

Commit b82b263

Browse files
caohy1988claude
andcommitted
fix: chain root cause in create_analytics_views() startup failure
Persist the init exception as _startup_error and use `raise ... from self._startup_error` so callers get actionable context instead of a generic RuntimeError. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 33f4e7e commit b82b263

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/google/adk/plugins/bigquery_agent_analytics_plugin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,7 @@ def __init__(
17631763
self.location = location
17641764

17651765
self._started = False
1766+
self._startup_error: Optional[Exception] = None
17661767
self._is_shutting_down = False
17671768
self._setup_lock = None
17681769
self.client = None
@@ -2141,7 +2142,7 @@ async def create_analytics_views(self) -> None:
21412142
if not self._started:
21422143
raise RuntimeError(
21432144
"Plugin initialization failed; cannot create analytics views."
2144-
)
2145+
) from self._startup_error
21452146
loop = asyncio.get_running_loop()
21462147
await loop.run_in_executor(self._executor, self._create_analytics_views)
21472148

@@ -2196,6 +2197,7 @@ def __getstate__(self):
21962197
state["offloader"] = None
21972198
state["parser"] = None
21982199
state["_started"] = False
2200+
state["_startup_error"] = None
21992201
state["_is_shutting_down"] = False
22002202
state["_init_pid"] = 0
22012203
return state
@@ -2224,6 +2226,7 @@ def _reset_runtime_state(self) -> None:
22242226
self.offloader = None
22252227
self.parser = None
22262228
self._started = False
2229+
self._startup_error = None
22272230
self._is_shutting_down = False
22282231
self._init_pid = os.getpid()
22292232

@@ -2247,7 +2250,9 @@ async def _ensure_started(self, **kwargs) -> None:
22472250
try:
22482251
await self._lazy_setup(**kwargs)
22492252
self._started = True
2253+
self._startup_error = None
22502254
except Exception as e:
2255+
self._startup_error = e
22512256
logger.error("Failed to initialize BigQuery Plugin: %s", e)
22522257

22532258
@staticmethod

tests/unittests/plugins/test_bigquery_agent_analytics_plugin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4943,5 +4943,10 @@ async def test_create_analytics_views_raises_on_startup_failure(
49434943
dataset_id=DATASET_ID,
49444944
table_id=TABLE_ID,
49454945
)
4946-
with pytest.raises(RuntimeError, match="Plugin initialization failed"):
4946+
with pytest.raises(
4947+
RuntimeError, match="Plugin initialization failed"
4948+
) as exc_info:
49474949
await plugin.create_analytics_views()
4950+
# Root cause should be chained for debuggability
4951+
assert exc_info.value.__cause__ is not None
4952+
assert "client boom" in str(exc_info.value.__cause__)

0 commit comments

Comments
 (0)