-
Notifications
You must be signed in to change notification settings - Fork 12
fix: Improve the error message when Application Default Credentials are not configured #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ | |
| PermissionDenied, | ||
| ) | ||
| from google.api_core.future.polling import POLLING_PREDICATE | ||
| from google.auth.exceptions import DefaultCredentialsError | ||
| from google.cloud.dataproc_spark_connect.client import DataprocChannelBuilder | ||
| from google.cloud.dataproc_spark_connect.exceptions import DataprocSparkConnectException | ||
| from google.cloud.dataproc_spark_connect.pypi_artifacts import PyPiArtifacts | ||
|
|
@@ -456,6 +457,15 @@ def create_session_pbar(): | |
| raise DataprocSparkConnectException( | ||
| f"Error while creating Dataproc Session: {e.message}" | ||
| ) | ||
| except DefaultCredentialsError as e: | ||
| stop_create_session_pbar_event.set() | ||
| if create_session_pbar_thread.is_alive(): | ||
| create_session_pbar_thread.join() | ||
| DataprocSparkSession._active_s8s_session_id = None | ||
| DataprocSparkSession._active_session_uses_custom_id = False | ||
|
Comment on lines
+461
to
+465
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This cleanup logic is duplicated in three different |
||
| raise DataprocSparkConnectException( | ||
| f"Error while creating Dataproc Session: {e}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably need to add a link to the ADC docs so users can fix it up more easily: https://docs.cloud.google.com/docs/authentication/provide-credentials-adc |
||
| ) | ||
| except Exception as e: | ||
| stop_create_session_pbar_event.set() | ||
| if create_session_pbar_thread.is_alive(): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1487,6 +1487,16 @@ def test_create_session_without_location(self): | |
| except DataprocSparkConnectException as e: | ||
| self.assertIn("location is not set", str(e)) | ||
|
|
||
| def test_create_session_without_application_default_credentials(self): | ||
| """Tests that an exception is raised when application default credentials is not provided.""" | ||
| os.environ.clear() | ||
| try: | ||
| DataprocSparkSession.builder.location("test-region").projectId( | ||
| "test-project" | ||
| ).getOrCreate() | ||
| except DataprocSparkConnectException as e: | ||
| self.assertIn("Your default credentials were not found", str(e)) | ||
|
Comment on lines
+1493
to
+1498
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better readability and to follow common testing patterns, consider using the with self.assertRaises(DataprocSparkConnectException) as e:
DataprocSparkSession.builder.location("test-region").projectId(
"test-project"
).getOrCreate()
self.assertIn("Your default credentials were not found", str(e.exception)) |
||
|
|
||
|
|
||
| class DataprocSparkConnectClientTest(unittest.TestCase): | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we check whether this will fix also #142 issue?