Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Stateful Validation Error Codes in Endpoint #1821

Merged
merged 26 commits into from
Nov 13, 2018

Conversation

Akvinikym
Copy link
Contributor

Description of the Change

Final part of introducing stateful validation error codes for commands - now they are added into transaction_processor, responses and endpoint.

Benefits

Error codes are in Iroha.

Possible Drawbacks

None.

Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
@Akvinikym Akvinikym requested review from muratovv, lebdron and l4l and removed request for lebdron October 30, 2018 10:27
@l4l l4l added needs-review pr awaits review from maintainers shared model labels Oct 30, 2018
@@ -58,12 +58,12 @@ namespace torii {

if (is_present) {
std::shared_ptr<shared_model::interface::TransactionResponse> response =
status_factory_->makeCommitted(request, "");
status_factory_->makeCommitted(request, "", 0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

I have two suggestions here:

  • Use default parameters from the factory.
  • And move error plus codes to one entity.
    It should be like
Suggested change
status_factory_->makeCommitted(request, "", 0, 0);
status_factory_->makeCommitted(request, TxStatusFactory::emptyError());

Where empty error returns class which contains: {error_msg, index, code}

if (not error.empty()) {
builder = builder.errorMsg(error);
if (not cmd_error.name.empty()) {
builder = builder.statelessErrorOrCmdName(cmd_error.name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Pls, avoid builders at all.

virtual const StatelessErrorOrFailedCommandNameType &
statelessErrorOrCommandName() const override;

virtual FailedCommandIndexType failedCommandIndex() const override;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe hash of the transaction is more appropriate here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The index can help during understanding, exactly which command failed in the given transaction, so this information is useful

@@ -67,13 +67,28 @@ namespace shared_model {
*/
virtual const ResponseVariantType &get() const = 0;

/// Message type
using ErrorMessageType = std::string;
/// Type of stateless validation error or of command name, which failed
Copy link
Contributor

Choose a reason for hiding this comment

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

seems the second of is redundant.

Signed-off-by: Akvinikym <[email protected]>
@Akvinikym Akvinikym changed the base branch from feature/stf-vld-err-codes to trunk/stf-rsp-err-codes November 12, 2018 09:04
@Akvinikym Akvinikym changed the base branch from trunk/stf-rsp-err-codes to dev November 12, 2018 09:05
@Akvinikym Akvinikym changed the base branch from dev to feature/stf-vld-err-codes November 12, 2018 09:05
auto status_factory =
std::make_shared<shared_model::proto::ProtoTxStatusFactory>();
auto tx_processor = std::make_shared<TransactionProcessorImpl>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we need status_factory to be in TransactionProcessor, so the latter is to be initialized after the factory

FailedCommandIndexType cmd_index_;
ErrorCodeType error_code_;

TransactionError() : cmd_name_{""}, cmd_index_{0}, error_code_{0} {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Quite redundant initialization

and errorMessage() == rhs.errorMessage() and get() == rhs.get();
and statelessErrorOrCommandName() == rhs.statelessErrorOrCommandName()
and failedCommandIndex() == rhs.failedCommandIndex()
and errorCode() == rhs.errorCode() and get() == rhs.get();
Copy link
Contributor

Choose a reason for hiding this comment

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

is comparison on get result is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why not? Two responses in theory can have similar values of those fields, but different response type, I think

@@ -292,19 +295,18 @@ TEST_F(ClientServerTest, SendTxWhenStatefulInvalid) {
ASSERT_EQ(client.sendTx(tx).answer, iroha_cli::CliClient::OK);

// fail the tx
auto cmd_name = "CommandName";
size_t cmd_index = 2;
uint32_t error_code = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Set please that value different from the cmd_index one
Test is a bit more precise in that case

Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
@Akvinikym Akvinikym changed the base branch from feature/stf-vld-err-codes to trunk/stf-rsp-err-codes November 13, 2018 12:07
@Akvinikym Akvinikym merged commit e86703d into trunk/stf-rsp-err-codes Nov 13, 2018
@Akvinikym Akvinikym deleted the feature/pcs-err-cds branch November 13, 2018 12:14
@l4l l4l removed the needs-review pr awaits review from maintainers label Nov 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants