Skip to content

Handle empty input in AddStringKeyStoreCommand #39490

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

Merged
merged 7 commits into from
Mar 15, 2019

Conversation

jkakavas
Copy link
Member

This change ensures that we do not make assumptions about the length
of the input that we can read from stdin and that we can handle empty
strings. The behavior remains the same with regards to the fact that we
don't accept multi-line input

Resolves: #39413

This change ensures that we do not make assumptions about the length
of the input that we can read from the stdin. It still consumes only
one line, as the previous implementation
@jkakavas jkakavas added >bug :Core/Infra/Settings Settings infrastructure and APIs v8.0.0 v7.2.0 labels Feb 28, 2019
@jkakavas jkakavas requested a review from rjernst February 28, 2019 05:53
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

}
value = writer.toCharArray();
} catch (IOException e) {
throw new UserException(ExitCodes.DATA_ERROR, e.getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

UserException is meant to be something clear for users which does not warrant a stack trace. Is the raw IOException message actually clear? What possible error scenarios exist?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, this was an oversight. IOException can be thrown by read() in the ByteBuffer, so I added a generic message and added the IOException as cause in the UserException

@jkakavas jkakavas requested a review from rjernst February 28, 2019 16:37
@jkakavas
Copy link
Member Author

jkakavas commented Mar 4, 2019

This is ready for another pass @rjernst , thanks

@jkakavas
Copy link
Member Author

Ping @rjernst

}
value = writer.toCharArray();
} catch (IOException e) {
throw new UserException(ExitCodes.DATA_ERROR, "Error reading the value from stdin", e);
Copy link
Member

Choose a reason for hiding this comment

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

This message is still opaque to a user. Remember UserException does not print a stacktrace. In this case, I think we should just let IOException bubble up and print the full stacktrace? What benefit is there in wrapping it? If there is a subclass of io errors that the user can directly do something about, then we should distinguish that and message appropriately with actions the user can take.

Copy link
Member Author

Choose a reason for hiding this comment

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

I got the idea to add the exceptions to the UserException from Jay's feedback in #38498 (comment) but I see what you're saying here. There is no subset of i/o errors that I know of where we could print something useful for the user, so I'll let the IOException be thrown

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

lgtm

@jkakavas jkakavas merged commit 5035c15 into elastic:master Mar 15, 2019
jkakavas added a commit that referenced this pull request Mar 15, 2019
This change ensures that we do not make assumptions about the length
of the input that we can read from the stdin. It still consumes only
one line, as the previous implementation
dnhatn pushed a commit to dnhatn/elasticsearch that referenced this pull request Aug 11, 2020
This change ensures that we do not make assumptions about the length
of the input that we can read from the stdin. It still consumes only
one line, as the previous implementation
dnhatn added a commit that referenced this pull request Aug 11, 2020
This change ensures that we do not make assumptions about the length
of the input that we can read from the stdin. It still consumes only
one line, as the previous implementation

Co-authored-by: Ioannis Kakavas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

elasticsearch-keystore utility crashes with NPE when passed 0-byte closed STDIN and -x
4 participants