Rethrow Loses Stack Trace (ARCH6154)
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.
Incorrect
Section titled “Incorrect”def load_profile(id) fetch(id)rescue Net::HTTPError raise ProfileError, "Could not load profile"endCorrect
Section titled “Correct”def load_profile(id) fetch(id)rescue Net::HTTPError => e raise ProfileError, "Could not load profile: #{id}"endRuby links the original exception as cause automatically; bind the handler variable with rescue => e so the chain is preserved.