Skip to content

Commit

Permalink
Merge pull request #51 from mgxd/fix/cap-tb
Browse files Browse the repository at this point in the history
FIX: Set cap on nipype traceback
  • Loading branch information
mgxd committed Nov 20, 2023
2 parents 880920a + 0a02e97 commit 887e808
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions migas/error/nipype.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from migas.error import strip_filenames

MAX_TRACEBACK_SIZE = 1500


def node_execution_error(etype: type, evalue: str, etb: TracebackType) -> dict:
strpval = evalue.replace('\n', ' ').replace('\t', ' ').strip()
Expand All @@ -22,6 +24,9 @@ def node_execution_error(etype: type, evalue: str, etb: TracebackType) -> dict:

if m := re.search(r'(?P<tb>(?<=Traceback:).*)', strpval):
tb = strip_filenames(m.group('tb')).strip()
# cap traceback size to avoid massive request
if len(tb) > 1500:
tb = f'{tb[:747]}...{tb[-750:]}'

return {
'status': 'F',
Expand Down
3 changes: 2 additions & 1 deletion migas/error/tests/test_nipype.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys

from migas.error.nipype import node_execution_error
from migas.error.nipype import node_execution_error, MAX_TRACEBACK_SIZE

ERROR_TEXT = """
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node failingnode.
Expand Down Expand Up @@ -63,3 +63,4 @@ def test_node_execution_error():
assert kwargs['status'] == 'F'
assert kwargs['error_type'] == 'NodeExecutionError'
assert 'FileNotFoundError' in kwargs['error_desc']
assert len(kwargs['error_desc']) <= MAX_TRACEBACK_SIZE

0 comments on commit 887e808

Please sign in to comment.