Skip to content

Commit b417875

Browse files
authored
Add better messaging for %statistics/%summary errors (#460)
* Add better messaging for %statistics/%summary errors * update changelog * Add messaging for StatisticsNotAvailableException --------- Co-authored-by: Michael Chin <chnmch@amazon.com>
1 parent f4546a0 commit b417875

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Starting with v1.31.6, this file will contain a record of major features and updates made in each release of graph-notebook.
44

55
## Upcoming
6+
- Added more helpful error messaging for `%statistics`/`%summary` ([Link to PR](https://github.com/aws/graph-notebook/pull/460))
67
- Added Neptune Notebook CloudFormation template ([Link to PR](https://github.com/aws/graph-notebook/pull/442))
78

89
## Release 3.7.2 (March 9, 2023)

src/graph_notebook/magics/graph_magic.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,24 @@ def get_load_ids(neptune_client):
241241
return ids, res
242242

243243

244+
def process_statistics_400(is_summary: bool, response):
245+
bad_request_res = json.loads(response.text)
246+
res_code = bad_request_res['code']
247+
if res_code == 'StatisticsNotAvailableException':
248+
print("No statistics found. Please ensure that auto-generation of DFE statistics is enabled by running "
249+
"'%statistics' and checking if 'autoCompute' if set to True. Alternately, you can manually "
250+
"trigger statistics generation by running: '%statistics --mode refresh'.")
251+
elif res_code == "BadRequestException":
252+
print("Unable to query the statistics endpoint. Please check that your Neptune instance is of size r5.large or "
253+
"greater in order to have DFE statistics enabled.")
254+
if is_summary and "Statistics is disabled" not in bad_request_res["detailedMessage"]:
255+
print("\nPlease also note that the Graph Summary API is only available in Neptune engine version 1.2.1.0 "
256+
"and later.")
257+
else:
258+
print("Query encountered 400 error, please see below.")
259+
print(f"\nFull response: {bad_request_res}")
260+
261+
244262
# TODO: refactor large magic commands into their own modules like what we do with %neptune_ml
245263
# noinspection PyTypeChecker
246264
@magics_class
@@ -424,6 +442,12 @@ def statistics(self, line, local_ns: dict = None):
424442
return
425443

426444
statistics_res = self.client.statistics(args.language, args.summary, mode)
445+
if statistics_res.status_code == 400:
446+
if args.summary:
447+
process_statistics_400(True, statistics_res)
448+
else:
449+
process_statistics_400(False, statistics_res)
450+
return
427451
statistics_res.raise_for_status()
428452
statistics_res_json = statistics_res.json()
429453
if not args.silent:
@@ -452,6 +476,9 @@ def summary(self, line, local_ns: dict = None):
452476
mode = "basic"
453477

454478
summary_res = self.client.statistics(args.language, True, mode)
479+
if summary_res.status_code == 400:
480+
process_statistics_400(True, summary_res)
481+
return
455482
summary_res.raise_for_status()
456483
summary_res_json = summary_res.json()
457484
if not args.silent:

0 commit comments

Comments
 (0)