Skip to content

Commit fd8c674

Browse files
committed
Log as warning rather than error, and with explicit message.
1 parent f2ad157 commit fd8c674

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/async/task.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,19 @@ def complete?
230230
private
231231

232232
# This is a very tricky aspect of tasks to get right. I've modelled it after `Thread` but it's slightly different in that the exception can propagate back up through the reactor. If the user writes code which raises an exception, that exception should always be visible, i.e. cause a failure. If it's not visible, such code fails silently and can be very difficult to debug.
233-
# As an explcit choice, the user can start a task which doesn't propagate exceptions. This only applies to `StandardError` and derived tasks. This allows tasks to internally capture their error state which is raised when invoking `Task#result` similar to how `Thread#join` works. This mode makes {ruby Async::Task} behave more like a promise, and you would need to ensure that someone calls `Task#result` otherwise you might miss important errors.
234-
def fail!(exception = nil, propagate = true)
233+
def fail!(exception = false, propagate = true)
235234
@status = :failed
236235
@result = exception
237236

238-
if propagate
239-
raise
240-
elsif @finished.nil?
241-
# If no one has called wait, we log this as an error:
242-
Console.logger.error(self) {$!}
243-
else
244-
Console.logger.debug(self) {$!}
237+
if exception
238+
if propagate
239+
raise exception
240+
elsif @finished.nil?
241+
# If no one has called wait, we log this as a warning:
242+
Console.logger.warn(self, "Task may have ended with unhandled exception.", exception)
243+
else
244+
Console.logger.debug(self, exception)
245+
end
245246
end
246247
end
247248

0 commit comments

Comments
 (0)