Skip to content

Commit ce379a2

Browse files
author
Google Earth Engine Authors
committed
Modify error message when user relies on Earth Engine's OAuth project
PiperOrigin-RevId: 718036131
1 parent 016b82f commit ce379a2

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

python/ee/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,16 @@ def Initialize(
211211
adc_err = 'authenticating by using local Application Default Credentials'
212212
api_err = 'Earth Engine API has not been used in project ([0-9]+) before'
213213
matches = re.search(api_err, str(e))
214-
if (adc_err in str(e)) or (matches and oauth.is_sdk_project(matches[1])):
214+
oauth_project = '517222506229'
215+
oauth_project_err = (
216+
'Caller does not have required permission to use project ' +
217+
oauth_project
218+
)
219+
if (
220+
(adc_err in str(e))
221+
or (matches and oauth.is_sdk_project(matches[1]))
222+
or (oauth_project_err in str(e))
223+
):
215224
raise EEException(NO_PROJECT_EXCEPTION) from None
216225
raise e
217226

python/ee/tests/ee_test.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def CheckDataInit(**kwargs):
8383
cred_args['quota_project_id'] = None
8484
expected_project = 'qp2'
8585
ee.Initialize()
86+
self.assertEqual(4, inits.call_count)
8687

8788
google_creds = google_creds.with_quota_project(None)
8889
with self.assertRaisesRegex(ee.EEException, '.*no project found..*'):
@@ -93,17 +94,29 @@ def CheckDataInit(**kwargs):
9394
with moc(ee.ApiFunction, 'initialize', side_effect=ee.EEException(msg)):
9495
with self.assertRaisesRegex(ee.EEException, '.*no project found..*'):
9596
ee.Initialize()
97+
self.assertEqual(4, inits.call_count)
98+
99+
oauth_project = '517222506229'
100+
expected_project = oauth_project
101+
msg = (
102+
'Caller does not have required permission to use project ' +
103+
oauth_project
104+
)
105+
with moc(ee.ApiFunction, 'initialize', side_effect=ee.EEException(msg)):
106+
with self.assertRaisesRegex(ee.EEException, '.*no project found..*'):
107+
ee.Initialize(project=oauth_project)
108+
self.assertEqual(5, inits.call_count)
96109

97110
cred_args['client_id'] = '123456789-xxx'
98111
cred_args['refresh_token'] = 'rt'
99112
expected_project = '123456789'
100113
ee.Initialize()
101-
self.assertEqual(5, inits.call_count)
114+
self.assertEqual(6, inits.call_count)
102115

103116
cred_args['client_id'] = '764086051850-xxx' # dummy usable-auth client
104117
with self.assertRaisesRegex(ee.EEException, '.*no project found..*'):
105118
ee.Initialize()
106-
self.assertEqual(5, inits.call_count)
119+
self.assertEqual(6, inits.call_count)
107120

108121
def testCallAndApply(self):
109122
"""Verifies library initialization."""

0 commit comments

Comments
 (0)