Skip to content

Commit e3bce0e

Browse files
oakbaniMichael Ng
authored andcommitted
refact: Output error trace when callback execution fails (#212)
1 parent 99512e4 commit e3bce0e

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ Style/SignalException:
4747

4848
Lint/RescueException:
4949
Enabled: false
50+
51+
Layout/EndOfLine:
52+
EnforcedStyle: lf

lib/optimizely/config_manager/async_scheduler.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ def execution_wrapper(callback)
7575
loop do
7676
begin
7777
callback.call
78-
rescue
78+
rescue StandardError => e
7979
@logger.log(
8080
Logger::ERROR,
81-
'Something went wrong when running passed function.'
81+
"Something went wrong when executing passed callback. #{e.message}"
8282
)
8383
stop!
8484
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Copyright 2019, Optimizely and contributors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
require 'spec_helper'
19+
require 'optimizely/config_manager/async_scheduler'
20+
require 'optimizely/logger'
21+
22+
describe Optimizely::AsyncScheduler do
23+
it 'should log error trace when callback fails to execute' do
24+
def some_callback(_args); end
25+
26+
spy_logger = spy('logger')
27+
28+
scheduler = Optimizely::AsyncScheduler.new(method(:some_callback), 10, false, spy_logger)
29+
scheduler.start!
30+
31+
while scheduler.running; end
32+
expect(spy_logger).to have_received(:log).with(
33+
Logger::ERROR,
34+
'Something went wrong when executing passed callback. wrong number of arguments (given 0, expected 1)'
35+
)
36+
end
37+
end

0 commit comments

Comments
 (0)