Skip to content

Commit 60c0448

Browse files
committed
Improve UDF error messages
1 parent d115204 commit 60c0448

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

singlestoredb/functions/ext/asgi.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import textwrap
4343
import threading
4444
import time
45+
import traceback
4546
import typing
4647
import urllib
4748
import uuid
@@ -709,21 +710,21 @@ class Application(object):
709710
error_response_dict: Dict[str, Any] = dict(
710711
type='http.response.start',
711712
status=500,
712-
headers=[(b'content-type', b'application/json')],
713+
headers=[(b'content-type', b'text/plain')],
713714
)
714715

715716
# Timeout response start
716717
timeout_response_dict: Dict[str, Any] = dict(
717718
type='http.response.start',
718719
status=504,
719-
headers=[(b'content-type', b'application/json')],
720+
headers=[(b'content-type', b'text/plain')],
720721
)
721722

722723
# Cancel response start
723724
cancel_response_dict: Dict[str, Any] = dict(
724725
type='http.response.start',
725726
status=503,
726-
headers=[(b'content-type', b'application/json')],
727+
headers=[(b'content-type', b'text/plain')],
727728
)
728729

729730
# JSON response start
@@ -1247,12 +1248,10 @@ async def __call__(
12471248
'timeout': func_info['timeout'],
12481249
},
12491250
)
1250-
body = json.dumps(
1251-
dict(
1252-
error='[TimeoutError] Function call timed out after ' +
1253-
str(func_info['timeout']) +
1254-
' seconds',
1255-
),
1251+
body = (
1252+
'TimeoutError: Function call timed out after ' +
1253+
str(func_info['timeout']) +
1254+
' seconds'
12561255
).encode('utf-8')
12571256
await send(self.timeout_response_dict)
12581257

@@ -1265,11 +1264,7 @@ async def __call__(
12651264
'function_name': func_name.decode('utf-8'),
12661265
},
12671266
)
1268-
body = json.dumps(
1269-
dict(
1270-
error='[CancelledError] Function call was cancelled',
1271-
),
1272-
).encode('utf-8')
1267+
body = b'CancelledError: Function call was cancelled'
12731268
await send(self.cancel_response_dict)
12741269

12751270
except Exception as e:
@@ -1282,11 +1277,12 @@ async def __call__(
12821277
'exception_type': type(e).__name__,
12831278
},
12841279
)
1285-
body = json.dumps(
1286-
dict(
1287-
error=f'[{type(e).__name__}] {str(e).strip()}',
1288-
),
1289-
).encode('utf-8')
1280+
msg = traceback.format_exc().strip().split(' File ')[-1]
1281+
if msg.startswith('"/tmp/ipykernel_'):
1282+
msg = 'Line ' + msg.split(', line ')[-1]
1283+
else:
1284+
msg = 'File ' + msg
1285+
body = msg.encode('utf-8')
12901286
await send(self.error_response_dict)
12911287

12921288
finally:

0 commit comments

Comments
 (0)