Skip to content

Commit 887e808

Browse files
authored
Merge pull request #51 from mgxd/fix/cap-tb
FIX: Set cap on nipype traceback
2 parents 880920a + 0a02e97 commit 887e808

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

migas/error/nipype.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from migas.error import strip_filenames
55

6+
MAX_TRACEBACK_SIZE = 1500
7+
68

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

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

2631
return {
2732
'status': 'F',

migas/error/tests/test_nipype.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22

3-
from migas.error.nipype import node_execution_error
3+
from migas.error.nipype import node_execution_error, MAX_TRACEBACK_SIZE
44

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

0 commit comments

Comments
 (0)