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

better handling of invocationtargetexception #968

Merged
merged 3 commits into from Jul 5, 2018
Merged

better handling of invocationtargetexception #968

merged 3 commits into from Jul 5, 2018

Conversation

SrinivasanTarget
Copy link
Member

Change list

Better handling of invocationtargetexception thrown during creating session

Thanks @iddol.

Types of changes

What types of changes are you proposing/introducing to Java client?
Put an x in the boxes that apply

  • No changes in production code.
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

@mykola-mokhnach FYI

Throwable cause = e.getCause();
throw new SessionNotCreatedException(
format("Unable to create new remote session. desired capabilities = %s"
+ "and reason is " + cause.getMessage(), desired));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not to use format specifiers for both arguments?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it might be handy to pass the original exception as cause constructor argument, so it would be easier to debug it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwable cause = e.getCause();
                        throw new SessionNotCreatedException(
                                format("Unable to create new remote session. desired capabilities = %s"
                                        + "and reason is %s", desired, cause != null ? cause.getMessage() : null,
                                        e.getTargetException()));

@mykola-mokhnach Do you mean it this way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost. It's just instead of setting reason to null if cause is null you set it to the original exception value

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also SessionNotCreatedException has the second constructor where one can provide the cause:

SessionNotCreatedException(String msg, Throwable cause)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i used the same constructor above.

throw new WebDriverException(format("It is impossible to create a new session "
+ "because 'createSession' which takes %s, %s and %s was not found "
+ "or it is not accessible",
HttpClient.class.getSimpleName(),
InputStream.class.getSimpleName(),
long.class.getSimpleName()), e);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it be that getCause returns null?

throw new SessionNotCreatedException(
format("Unable to create new remote session. desired capabilities = %s"
+ "and reason is " + cause.getMessage(), desired));
format("Unable to create new remote session. desired capabilities = %s", desired), e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

desired capabilities = %s -> Desired capabilities: %s

@SrinivasanTarget SrinivasanTarget merged commit 3c05402 into appium:master Jul 5, 2018
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

Successfully merging this pull request may close these issues.

None yet

2 participants