-
-
Notifications
You must be signed in to change notification settings - Fork 482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Context for Custom Exceptions #479
Comments
While I realize patching isn't overly frowned upon in Ruby, it'd likely be better if we continue to provide an abstraction that is like |
I not sure what you mean by "patching". I'm proposing that we add an API to provide context for custom exception classes. You could also do this in Java, for example, by implementing an Interface. I don't like the Another option is that we have something like the processor system, where you could register annotation handler for specific exception classes. But this would still require me to store the info inside the exception class and I would have to take care of an initializer, that registers this annotations for all my custom exception classes. (*) We could completely decouple by calling my custom |
@philipp-spiess are you just looking to throw up a bunch of metadata along with an exception? e.g. I think I understand the value, but it's a bit of an overload on what context is today. It's generally not exception specific, but its environment based. That is, context is often things like "whats the current state of foo". I definitely understand the desire to not couple your code to Sentry, but quite frankly, once you use Sentry you don't stop using it. There is absolutely a line you'd need to draw that says "this kind of data is valuable". Once you do, the fact that you're coupled to something is insignificant. You could just as easily make an |
This is exactly what we're looking for - metadata so we can recreate the conditions that lead to this exception. You can achieve this currently by setting a member variable and
I agree 😄 (1). # raven-ruby/event.rb
exc.instance_variable_defined?(:@__raven_context) && exc.instance_variable_get(:@__raven_context) |
Take a look at #491 and tell me what you think. |
This is amazing 👍 |
Fixed by #491, available in 1.0.0+. |
I think adding Context to a Custom Exception through the
@__raven_context
member variable (see here and here) is not ideal. To improve this, I suggest two changes:Switch from a member variable to an actual public method. This allows us for a more straight forward API design and doesn't require the context to be set during initialisation.
We should use
deep_merge
instead of a regularmerge
. This way we won't override global context options. See hereImagine the previous
CustomException
with the followingRaven
call:A regular
#merge
would look like this:Compared to a
#deep_merge
implementation, which would preserve previous the context.The problem with
#deep_merge
is that it would require another dependency as it's not part of the standard library. But simple implementations are available.The text was updated successfully, but these errors were encountered: