Skip to content

Commit f14ac8e

Browse files
committed
Prepend traceback info to trackusage exception messages
1 parent 199864c commit f14ac8e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

bidscoin/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import warnings
2727
import tempfile
2828
import subprocess
29+
import traceback
2930
from pathlib import Path
3031
from importlib import metadata
3132
from typing import Union
@@ -191,6 +192,9 @@ def trackusage(event: str, message='', dryrun: bool=False) -> dict:
191192
'userid': hashlib.md5(getpass.getuser().encode('utf8')).hexdigest(),
192193
'hostid': hashlib.md5(platform.node().encode('utf8')).hexdigest()}
193194
if message:
195+
if isinstance(message, Exception):
196+
trace = traceback.extract_tb(traceback.sys.exc_info()[2])[-1] # Get the last traceback entry
197+
message = f"({trace.filename},{trace.lineno}){message}" # Prepend the traceback info
194198
data['message'] = str(message)
195199
if container := os.getenv('CONTAINER'):
196200
data['container'] = container
@@ -211,7 +215,7 @@ def trackusage(event: str, message='', dryrun: bool=False) -> dict:
211215
return data
212216
tracked[event] = now
213217

214-
# If something goes wrong, add an error message, clear the shelf and return
218+
# If something goes wrong, add an error message, clear the shelf and return if we can't sleep
215219
except Exception as shelveerror:
216220
data['event'] = 'trackusage_exception'
217221
data['message'] = f"({event}){shelveerror}"

0 commit comments

Comments
 (0)