Skip to content

Commit f76e73a

Browse files
author
Ghislain Fourny
committed
Better error formatting for errors happing only upon collecting results.
1 parent 6bcb234 commit f76e73a

1 file changed

Lines changed: 60 additions & 4 deletions

File tree

src/jsoniqmagic/magic.py

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,80 @@ def run(self, line, cell=None, timed=False):
6767
"""
6868

6969
if(args.pyspark_data_frame):
70-
df = response.df();
70+
try:
71+
df = response.df();
72+
except Py4JJavaError as e:
73+
print(e.java_exception.getMessage())
74+
return
75+
except Exception as e:
76+
print("Query unsuccessful.")
77+
print("Usual reasons: firewall, misconfigured proxy.")
78+
print("Error message:")
79+
print(e.args[0])
80+
return
81+
except:
82+
print("Query unsuccessful.")
83+
print("Usual reasons: firewall, misconfigured proxy.")
84+
return
7185
if df is not None:
7286
df.show()
7387

7488
if (args.pandas_data_frame):
75-
pdf = response.pdf()
89+
try:
90+
pdf = response.pdf()
91+
except Py4JJavaError as e:
92+
print(e.java_exception.getMessage())
93+
return
94+
except Exception as e:
95+
print("Query unsuccessful.")
96+
print("Usual reasons: firewall, misconfigured proxy.")
97+
print("Error message:")
98+
print(e.args[0])
99+
return
100+
except:
101+
print("Query unsuccessful.")
102+
print("Usual reasons: firewall, misconfigured proxy.")
103+
return
76104
if pdf is not None:
77105
print(pdf)
78106

79107
if (args.apply_updates):
80108
if ("PUL" in response.availableOutputs()):
81-
response.applyPUL()
109+
try:
110+
response.applyPUL()
111+
except Py4JJavaError as e:
112+
print(e.java_exception.getMessage())
113+
return
114+
except Exception as e:
115+
print("Query unsuccessful.")
116+
print("Usual reasons: firewall, misconfigured proxy.")
117+
print("Error message:")
118+
print(e.args[0])
119+
return
120+
except:
121+
print("Query unsuccessful.")
122+
print("Usual reasons: firewall, misconfigured proxy.")
123+
return
82124
print("Updates applied successfully.")
83125
else:
84126
print("No Pending Update List (PUL) available to apply.")
85127

86128
if (args.json or (not args.pandas_data_frame and not args.pyspark_data_frame)):
87-
capplusone = response.take(rumble.getRumbleConf().getResultSizeCap() + 1)
129+
try:
130+
capplusone = response.take(rumble.getRumbleConf().getResultSizeCap() + 1)
131+
except Py4JJavaError as e:
132+
print(e.java_exception.getMessage())
133+
return
134+
except Exception as e:
135+
print("Query unsuccessful.")
136+
print("Usual reasons: firewall, misconfigured proxy.")
137+
print("Error message:")
138+
print(e.args[0])
139+
return
140+
except:
141+
print("Query unsuccessful.")
142+
print("Usual reasons: firewall, misconfigured proxy.")
143+
return
88144
if len(capplusone) > rumble.getRumbleConf().getResultSizeCap():
89145
count = response.count()
90146
print("The query output %s items, which is too many to display. Displaying the first %s items:" % (count, rumble.getRumbleConf().getResultSizeCap()))

0 commit comments

Comments
 (0)