Ir al contenido

Rethrow Loses Stack Trace (ARCH6154)

Esta página aún no está disponible en tu idioma.

Key ruby.logging.reraise-loses-cause · Severity info · Category logging

Raising a new exception inside a handler without binding the cause destroys the original stack trace and root cause. This makes debugging far harder.

def load_profile(id)
fetch(id)
rescue Net::HTTPError
raise ProfileError, "Could not load profile"
end
def load_profile(id)
fetch(id)
rescue Net::HTTPError => e
raise ProfileError, "Could not load profile: #{id}"
end

Ruby links the original exception as cause automatically; bind the handler variable with rescue => e so the chain is preserved.