Skip to content

Commit c2cd37f

Browse files
committed
fix: Prevent usage of Oj once requiring it already raised an exception
Fixes the following exception, which happens, when the require statement has raised an exception, but only after the 'Oj' name is already defined. ```` E, [2024-04-29T13:33:24.549280 #108] ERROR -- : undefined method `dump' for Oj:Module defined?(Oj) ? Oj.dump(data, mode: :strict) : JSON.dump(data) ^^^^^ Did you mean? dup ``` Signed-off-by: Ferenc Géczi <[email protected]>
1 parent 8e4ede2 commit c2cd37f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/instana/backend/request_client.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
# :nocov:
99
begin
1010
require 'oj'
11+
INSTANA_USE_OJ = true
1112
rescue LoadError => _e
1213
Instana.logger.warn("Unable to load Oj.")
14+
INSTANA_USE_OJ = false
1315
end
1416
# :nocov:
1517

@@ -66,7 +68,7 @@ def send_request(method, path, data = nil, headers = {})
6668

6769
def encode_body(data)
6870
# :nocov:
69-
defined?(Oj) ? Oj.dump(data, mode: :strict) : JSON.dump(data)
71+
INSTANA_USE_OJ ? Oj.dump(data, mode: :strict) : JSON.dump(data)
7072
# :nocov:
7173
end
7274
end

0 commit comments

Comments
 (0)