Skip to content

Commit f37f8e4

Browse files
authored
Log as warning rather than error, and with explicit message. (#170)
1 parent 8e328cf commit f37f8e4

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
@@ -224,18 +224,19 @@ def complete?
224224
private
225225

226226
# 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.
227-
# 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.
228-
def fail!(exception = nil, propagate = true)
227+
def fail!(exception = false, propagate = true)
229228
@status = :failed
230229
@result = exception
231230

232-
if propagate
233-
raise
234-
elsif @finished.nil?
235-
# If no one has called wait, we log this as an error:
236-
Console.logger.error(self) {$!}
237-
else
238-
Console.logger.debug(self) {$!}
231+
if exception
232+
if propagate
233+
raise exception
234+
elsif @finished.nil?
235+
# If no one has called wait, we log this as a warning:
236+
Console.logger.warn(self, "Task may have ended with unhandled exception.", exception)
237+
else
238+
Console.logger.debug(self, exception)
239+
end
239240
end
240241
end
241242

0 commit comments

Comments
 (0)