better handling of invocationtargetexception by SrinivasanTarget · Pull Request #968 · appium/java-client

Conversation

@SrinivasanTarget

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

mykola-mokhnach

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

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?

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.

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?

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

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)

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.

mykola-mokhnach

InputStream.class.getSimpleName(),
long.class.getSimpleName()), e);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();

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?

mykola-mokhnach

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);

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

mykola-mokhnach

2 participants

@SrinivasanTarget @mykola-mokhnach