Skip to content
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

Command failed java.lang.reflect.UndeclaredThrowableException #63

Closed
ghost opened this issue Feb 10, 2015 · 8 comments
Closed

Command failed java.lang.reflect.UndeclaredThrowableException #63

ghost opened this issue Feb 10, 2015 · 8 comments

Comments

@ghost
Copy link

ghost commented Feb 10, 2015

SimpleExecutionStrategy throwing UndeclaredThrowableException at ReflectionUtils.invokeMethod.

How do we register (if that is the correct word) our application exceptions that might occur within a command ? I need to capture thrown exceptions correctly.

For example this command makes a remote connection to a service and might fail for a number of reasons.

 @CliCommand(value = "ife scep ca", help = "SCEP get CA certificate")
    public final String ca() throws ClientException, IOException {
        this.cacert = auto.getCaCertificate();
        return "Got CA certificate CN " + this.cacert.getSubjectDN().getName();
    }

I have tried implements ExecutionProcessor also no luck as of yet (exception is null).

Paul

@ericbottard
Copy link
Member

Can you clarify exactly what you want to achieve?

If you want to catch exceptions inside the command implementations, then you are certainly allowed to do that (and act on it).
If you simply let exceptions bubble up, then their toString() will be displayed in the shell (in a different color)
Lastly, you may want to have a look at ExecutionProcessor to intercept exceptions globally

@ghost
Copy link
Author

ghost commented Feb 11, 2015

Hi Eric, Thank you for getting back to me I have the following test case:

=======================================
*                                     *
*           IFE TOOLBELT              *
*                                     *
=======================================
Version:1.1.27
Welcome to the IFE Toolbelt CLI
ife-shell>ife scep enroll --CN *.gw.be.msm.internal --PROXY true
2015-02-11 10:26:37 [ParseResult@586218a3 method = enroll@SCEPCommands, instance = com.moneysupermarket.tools.ife.spring.shell.commands.SCEPCommands@746dd488, arguments = '*.gw.be.msm.internal,true']
2015-02-11 10:26:37 Fetching CA certificate from MSMCA[ejbca.msm.internal] destination root /etc/pki/msm
2015-02-11 10:26:37 Retrieving current CA certificate
2015-02-11 10:26:38 Sending GetCACert(MSMCA) to http://ejbca.msm.internal:8080/ejbca/publicweb/apply/scep/pkiclient.exe?operation=GetCACert&message=MSMCA
Command failed java.lang.reflect.UndeclaredThrowableException
2015-02-11 10:26:38 

We can clearly see the message from beforeInvocation() (ExecutionProcessor) but it never hits the afterThrowingInvocation().

I had added:

 @Override
    public void afterThrowingInvocation(ParseResult pr, Throwable thrwbl) {
         LOGGER.warn(thrwbl.getLocalizedMessage());
        //
    }   

Am I hitting a bug or doing something wrong ?

Paul

@ericbottard
Copy link
Member

May getLocalizedMessage() is blank?
More importantly, what are you trying to achieve in this case? What should happen when an exception happens? Knowing that, maybe I can point you to the best implementation solution.

@ghost
Copy link
Author

ghost commented Feb 11, 2015

Thanks, so maybe an example of a command that calls some code that throws an exception like filenotfoundexception and then being able to catch that exception and print it to the shell console.

@prongs
Copy link

prongs commented Nov 30, 2015

Any examples?

@ericbottard
Copy link
Member

Tidying old 1.x issues

@prongs
Copy link

prongs commented Aug 16, 2017

When is spring 2.x getting released?

@ericbottard
Copy link
Member

SNAPSHOTs are already available based on the master branch. Milestones are coming in the upcoming weeks. Have a look at the samples on master if you're interested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants