Transports: drop broken super call in InternalErrorResponse#to_s#5762
Transports: drop broken super call in InternalErrorResponse#to_s#5762p-datadog wants to merge 4 commits into
Conversation
The TransportError raised from Datadog::Core::Remote::Client#sync used response.to_s as the message. Neither Datadog::Core::Transport::Response nor Datadog::Core::Transport::HTTP::Response defines to_s, and InternalErrorResponse#to_s calls super, which falls through to Object#to_s and produces "#<...:0xADDR>" with no useful information. Switching the raise site to response.inspect resolves super to Response#inspect, which already emits the predicates, optional HTTP code, and truncated payload — and InternalErrorResponse#inspect appends the wrapped error_type and error message. Reported in https://github.com/DataDog/ruby-guild/issues/241.
Strengthen the existing assertions in client_spec.rb so they fail if the raise site reverts to response.to_s. The internal_error?:true prefix is emitted by Response#inspect; with response.to_s the message would start with #<...:0xADDR> and the prefix would be absent.
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 958cda0 | Docs | Datadog PR Page | Give us feedback! |
Revert "RC: include response details in TransportError message" Switching approach: fix InternalErrorResponse#to_s directly instead of changing the raise site. The previous approach only swapped an "#<...:0xADDR>" prefix for a string of mostly-nil predicates without adding signal beyond what PR #4669 already produces.
The Response module does not define to_s, so the super call in InternalErrorResponse#to_s resolves to Object#to_s and emits "#<Datadog::Core::Transport::InternalErrorResponse:0xADDR>" as the prefix of the error message — replacing the wrapped exception info that follows with a memory address. Replace super with self.class so the prefix is the class name rather than the default object identifier. The trailing "error_type:<klass> error:<message>" portion (already useful since PR #4669 added AgentErrorResponse with an informative message) is unchanged. Reported in https://github.com/DataDog/ruby-guild/issues/241.
BenchmarksBenchmark execution time: 2026-05-13 23:33:13 Comparing candidate commit 958cda0 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 45 metrics, 1 unstable metrics.
|
What does this PR do?
Replaces the
supercall inDatadog::Core::Transport::InternalErrorResponse#to_swithself.class, so the prefix of the error message is the class name instead of#<…:0xADDR>.Motivation:
Reported in https://github.com/DataDog/ruby-guild/issues/241 (originally surfaced via APMS-15827).
InternalErrorResponseincludes theResponsemodule and defines bothto_sandinspectwith the same body —"#{super}, error_type:#{error.class} error:#{error}"— apparently assuming the module defines both methods symmetrically. It doesn't:Responsedefinesinspectonly.Method resolution order is
InternalErrorResponse→Response(module) →Object.inspect'ssuperfindsResponse#inspectand returns the predicates-and-payload string.to_s'ssuperskipsResponse(noto_sthere) and lands onObject#to_s, whose default implementation returns"#<ClassName:0x<hex address>>". So the samesuperpattern works in one method and silently emits a memory address in the other.The trailing
error_type:<klass> error:<message>portion is already useful (PR #4669 wraps agent HTTP errors inAgentErrorResponsewhose message includes the response code and truncated body), so this PR only fixes the leading garbage. TheTransportErrorraise site inDatadog::Core::Remote::Client#syncis unchanged — it still callsresponse.to_s, butto_snow produces a clean string.Change log entry
Yes. Remote configuration
TransportErrormessages no longer include the wrapper response object's memory address.Additional Notes:
Before / after (
Datadog::Core::Remote::Client::TransportError#messagefor the twointernal_error?paths):Network error (
IOError):Before:
After:
Agent HTTP 500:
Before:
After:
How to test the change?
Two new assertions in
spec/datadog/core/transport/response_spec.rbpin the new behavior:#to_smust not contain0x\h+and must start withDatadog::Core::Transport::InternalErrorResponse,. The pre-existing/StandardError/assertion still passes.