How to get FailureType in fallback method when using #HystrixCommand - hystrix

I can get Throwable obj in fallback method, but I cannot tell the throwable which is maybe reaching semaphore limit exception(SEMAPHORE_REJECTED)or maybe circuit-break open exception or my defined exception.
Maybe I can determine it by error message, howerver it's clumsy.
Or is there any way to get HystrixCommand obj in fallback method using command key?
Thx a lot!!!

I've found a method though it's a bit cumbersome.
HystrixPlugins.getInstance().registerCommandExecutionHook(new HystrixCommandExecutionHook() {// override onXXX method}
Perhaps there is a better approach or api.

Related

Is there a way to abort the processing of a Routing Slip without throwing an Exception?

I have a routing slip that has a handful of steps. I want to be able to include steps that perform some validation that can short-circuit the routing slip if needed.
I have:
from("direct:Start")
.setHeader(header("RoutingSlip", config::getRoutingSlip)
.doTry()
.routingSlip(header("RoutingSlip"))
.doEndTry()
.doCatch(ValidationException.class)
.log("Validation failed!")
.end()
Is this the best way to do this?
The fact that there is a stacktrace being logged makes me question if this is the right way to do this.
Thanks.
Could you try to replace your raising exception code by setting
the property Exchange.ROUTE_STOP to true
ie.
exchange.setProperty(Exchange.ROUTE_STOP, Boolean.TRUE);

Codename One: log which code is calling another code

This question is referring to Codename One only.
Short story: I'm debugging a strange bug that occurs only in real devices but not in the Simulator. There is method that is called every second in a particular circumstance, so I suspected a timer. But which timer? To investigate who is calling this method:
I enabled setEnableAsyncStackTraces(true) (https://www.codenameone.com/blog/better-error-logging.html)
I inserted this exception in the method: throw new IllegalStateException("Who Is Calling me?");
After that, I discovered which timer is calling my method. However, this way to debug is not always praticable, because it forces me to insert an exception that crashes the app.
Do you have a suggestion? Do you think that a new API like Log.printAsyncStackTrace() can be useful in these cases?
Thank you
You can use something like this:
try {
throw new RuntimeException("This is the caller");
} catch(RuntimeException e) {
Log.e(e);
Log.sendLogAsync();
}
It's not as efficient as it should be but a log won't be much more efficient and might be abused by developers. At least this looks bad enough so developers know not to leave it in production.

What's is the right way to trigger an error callback in Backbone if my response has a certain flag?

This is my use case: I call fetch on a collection and receive a JSON from my server yet I have an error flag. This will always trigger the success flow, and I can detect the error by 2 means:
In my parse method - which is ugly.
By not using the success option, and using the Deferred's Done callback to check for the error. This is ugly as well since I have to call parse myself afterwards.
This would be solveable if Backbone had a validate function on collection but it doesn't...
Any suggestions?
EDIT: I know there's a way to do it by supplying my own Sync method but I got a bit lost there...
good question.. I'm not sure it's so bad to work with the parse method. It's name doesn't fit but it's all you've got in the natural path of the code and I guess you can just return an empty list without breaking anything.
The question to me is what is the cause of the error? If it's, say, a permissions thing (or some other error covered by the http protocol), you could return an error code from the server which should trigger your error callback..

How to find out the exact operation that is posted to Dispatcher

Is there a way where we can find out which UI element has posted an operation to the Dispatcher queue which eventually throws the event ,System.Windows.Threading.Dispatcher.CurrentDispatcher.Hooks.OperationPosted
Update : A private property DispatcherOperation.Name is showing what I need in the VS mouse-over in debugging mode. I just need to print this name to a logger for other debugging purposes. Is it possible to extract the Name dynamically.
Yes it is possible, while i give you a way to do it, i must warn you though, using reflection to get private or protected fields/properties/methods is never a good idea because first they are usually private for a reason and second of all if the signature or interface changes you code might break. But because you said it is just for debugging, this might be a valuable solution.
You can always use Reflection for these kind of things. First you need the Type and Instance of the object you want to read its private properties. Unfortunately i don't know if the Name you are looking for is a field or a property, but the overall procedure is similar. First get the property with GetProperty and then call GetValue on the returned PropertyInfo object. You might want to cache the PropertyInfo object to gain some speed while debug. You also need to use the correct BindingFlags again i don't know exactly how the field/property is described so i can't give you the exact code, but from here it should be easy to figure out.
Hope that helps.

Silverlight 3 XamlReader Exception not caught

when I use XamlReader.Load() with an invalid XAML string, the resulting XAMLParseException is not caught although beeing in a try-catch-block:
try
{
UIElement xamlCode = XamlReader.Load(XamlText) as UIElement;
}
catch (Exception ex)
{
ErrorText = ex.Message;
}
The code is called from the Tick-Event of a DispatcherTimer, but also in Events like MouseLeftButtonDown the exception is not caught resulting in a break in the Line where I call .Load().
Does anyone know how to catch this Exception and resume normal programm activity?
Thanks, Andrej
It is completely unfathomable that this code would not catch the exception. How do you determine that the XAMLParseException is occuring here? Are you sure is not coming from some other Xaml Load in the project?
Is this always the case ? or onlys while debugging ?
I'm aware this is an extremely late answer and you might have found the solution to it, for as reference to people finding your question similar to theirse (like my case ), my answer might still be of use.
If its happening while debuggin, it might be because the exeption is configured to be thrown.
You can change this:
Customize the Debug menu, adding the "Exceptions" command to it.
In the Exceptions configuration, Drill down to System.Windows.Markup.XamlParseException, which is under Common Language Runtime Exceptions.
Remove the check from the "Throw" column.
There are various Silverlight operations that get "re-marshalled" onto separate threads for what are presumably various good and sufficient reasons. It looks kind of like this:
Dispatcher.BeginInvoke(() => LoadSomeXamlOrSomething());
Any exception thrown within LoadSomeXamlOrSomething() won't be caught by normal try/catch blocks. This happens even in SL 4 with things like loading images with invalid formats. It's annoying, and MS needs to come up with a better way to handle this, for instance, by letting you register an exception handler when you make the call.
Until MS figures this out, your options are:
Fix the underlying XAML error.
Catch the exception in App.Application_UnhandledException.

Resources