Skip to content

Commit fc84292

Browse files
committed
Support PostgreSQL and SQLite nil value for column limit
They have variable size TEXT columns and return `nil` for the limit value. Just use the default TEXT size for MySQL as default.
1 parent a77d387 commit fc84292

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

app/models/solid_queue/failed_execution.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def retry
3434

3535
private
3636
JSON_OVERHEAD = 256
37-
DEFAULT_BACKTRACE_LINES_LIMIT = 400
37+
DEFAULT_ERROR_SIZE_LIMIT = 64.kilobytes
3838

3939
def expand_error_details_from_exception
4040
if exception
@@ -51,19 +51,21 @@ def exception_message
5151
end
5252

5353
def exception_backtrace
54-
if column = self.class.connection.schema_cache.columns_hash(self.class.table_name)["error"]
55-
limit = column.limit - exception_class_name.bytesize - exception_message.bytesize - JSON_OVERHEAD
54+
limit = determine_backtrace_size_limit
5655

57-
if exception.backtrace.to_json.bytesize <= limit
58-
exception.backtrace
59-
else
60-
truncate_backtrace(exception.backtrace, limit)
61-
end
56+
if exception.backtrace.to_json.bytesize <= limit
57+
exception.backtrace
6258
else
63-
exception.backtrace.take(DEFAULT_BACKTRACE_LINES_LIMIT)
59+
truncate_backtrace(exception.backtrace, limit)
6460
end
6561
end
6662

63+
def determine_backtrace_size_limit
64+
column = self.class.connection.schema_cache.columns_hash(self.class.table_name)["error"]
65+
66+
(column&.limit || DEFAULT_ERROR_SIZE_LIMIT) - exception_class_name.bytesize - exception_message.bytesize - JSON_OVERHEAD
67+
end
68+
6769
def truncate_backtrace(lines, limit)
6870
[].tap do |truncated_backtrace|
6971
lines.each do |line|

0 commit comments

Comments
 (0)