Skip to content

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

@mykola-mokhnach mykola-mokhnach Jul 5, 2018

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.

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.

2 participants