@@ -303,3 +303,54 @@ def test_v2_query_failed_error_details(mocker, test_context_mock):
303303 exception_str = str (exception .value )
304304 assert "COLUMN_NAME" in exception_str
305305 assert "my_table" in exception_str
306+
307+
308+ def test_v2_polling_error_includes_context (mocker , test_context_mock ):
309+ """Test that polling errors include query context for better debugging."""
310+ mocker .patch ("time.sleep" )
311+
312+ test_query = "SELECT * FROM `ri.foundry.main.dataset.test-dataset`"
313+
314+ # Mock the api_query endpoint (initial query execution)
315+ test_context_mock .mock_adapter .register_uri (
316+ "POST" ,
317+ build_api_url (TEST_HOST .url , "foundry-sql-server" , "sql-endpoint/v1/queries/query" ),
318+ json = {"type" : "running" , "running" : {"queryHandle" : {"queryId" : "test-query-id" , "type" : "foundry" }}},
319+ )
320+
321+ # Mock the api_status endpoint with polling error
322+ test_context_mock .mock_adapter .register_uri (
323+ "POST" ,
324+ build_api_url (TEST_HOST .url , "foundry-sql-server" , "sql-endpoint/v1/queries/status" ),
325+ json = {
326+ "status" : {
327+ "type" : "failed" ,
328+ "failed" : {
329+ "errorCode" : "ModuleGroupService:ErrorPollingModule" ,
330+ "errorInstanceId" : "5be87070-3aa3-4ed6-aa6a-d9b5041885af" ,
331+ "errorMessage" : "Error polling for job status. Please resubmit." ,
332+ "retryable" : False ,
333+ },
334+ }
335+ },
336+ )
337+
338+ with pytest .raises (FoundrySqlQueryFailedError ) as exception :
339+ test_context_mock .foundry_sql_server_v2 .query_foundry_sql (test_query )
340+
341+ # Verify error details are extracted
342+ assert exception .value .error_code == "ModuleGroupService:ErrorPollingModule"
343+ assert exception .value .error_instance_id == "5be87070-3aa3-4ed6-aa6a-d9b5041885af"
344+ assert exception .value .error_message == "Error polling for job status. Please resubmit."
345+
346+ # Verify query context is included in the error
347+ assert exception .value .query == test_query
348+ assert exception .value .branch == "master"
349+ assert exception .value .dialect == "SPARK"
350+
351+ # Verify context appears in exception string
352+ exception_str = str (exception .value )
353+ assert "query = " + test_query in exception_str
354+ assert "branch = master" in exception_str
355+ assert "dialect = SPARK" in exception_str
356+ assert "ModuleGroupService:ErrorPollingModule" in exception_str
0 commit comments