3 ms·
One thing I miss when the error object pattern is used in preference to exceptions is the stack trace. With an exception, you get a detailed log of the full st
by zmmmmm 4y ago
One thing I miss when the error object pattern is used in preference to exceptions is the stack trace.
With an exception, you get a detailed log of the full stack that led to the error. With an error object, I have to reverse engineer out all the places in the code that could potentially return that type of error. In a perfect world, you don't need to know that, and all the information you need is in the error object. But we don't live in a perfect world and very often the stack trace is the main lead you have to debug some crazy thing happening in production.
- akdor1154 4y agoYes i have hit this too. My planned goto approach if I was on a prod app instead of a toy, is to use something like `result`, but with the `Err` variant modded to generate an internal traceback whenever it's constructed. With that said i haven't ever done the above - anyone done something similar? Or approached this a different way?
- bb88 4y agoGiven enough digging around in the python runtime system I'm sure you can find the current stack trace and shove that in an error class. But now it's a lesser error than an exception. Any exception while processing your error will cause the stack to unwind and drop the error variable with the stack trace inside of it. Now if you raise an exception while in the handling of an exception, python will keep around both stack traces.