File tree Expand file tree Collapse file tree 1 file changed +36
-2
lines changed Expand file tree Collapse file tree 1 file changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -33,11 +33,45 @@ def retry
33
33
end
34
34
35
35
private
36
- BACKTRACE_LINES_LIMIT = 400
36
+ JSON_OVERHEAD = 256
37
37
38
38
def expand_error_details_from_exception
39
39
if exception
40
- self . error = { exception_class : exception . class . name , message : exception . message , backtrace : exception . backtrace . first ( BACKTRACE_LINES_LIMIT ) }
40
+ self . error = { exception_class : exception_class_name , message : exception_message , backtrace : exception_backtrace }
41
+ end
42
+ end
43
+
44
+ def exception_class_name
45
+ exception . class . name
46
+ end
47
+
48
+ def exception_message
49
+ exception . message
50
+ end
51
+
52
+ def exception_backtrace
53
+ if ( limit = determine_backtrace_size_limit ) && exception . backtrace . to_json . bytesize > limit
54
+ truncate_backtrace ( exception . backtrace , limit )
55
+ else
56
+ exception . backtrace
57
+ end
58
+ end
59
+
60
+ def determine_backtrace_size_limit
61
+ column = self . class . connection . schema_cache . columns_hash ( self . class . table_name ) [ "error" ]
62
+ if column . limit . present?
63
+ column . limit - exception_class_name . bytesize - exception_message . bytesize - JSON_OVERHEAD
64
+ end
65
+ end
66
+
67
+ def truncate_backtrace ( lines , limit )
68
+ [ ] . tap do |truncated_backtrace |
69
+ lines . each do |line |
70
+ if ( truncated_backtrace << line ) . to_json . bytesize > limit
71
+ truncated_backtrace . pop
72
+ break
73
+ end
74
+ end
41
75
end
42
76
end
43
77
end
You can’t perform that action at this time.
0 commit comments