Skip to content

Raise BrokenPreconditionError on invalid inputs#4957

Closed
pirapira wants to merge 1 commit into
raiden-network:developfrom
pirapira:broken-precondition-passed
Closed

Raise BrokenPreconditionError on invalid inputs#4957
pirapira wants to merge 1 commit into
raiden-network:developfrom
pirapira:broken-precondition-passed

Conversation

@pirapira
Copy link
Copy Markdown
Contributor

because the caller of the proxy should have checked these inputs.

The documentation for BrokenPreconditionError clearly says

class BrokenPreconditionError(RaidenError):
    """ Raised while checking transaction preconditions
    which should be satisfied before sending the transaction.
    This exception when:
    1. An assert or a revert in the smart contract would be hit for
    triggering block.

    2. If provided values are invalid (i.e ValueError)
    """

So, when the provided values are invalid, BrokenPreconditionError
should be raised.

This PR comes from a discussion in #4936 (review)

Description

Please, describe what this PR does in detail:

  • If it's a bug fix, detail the root cause of the bug and how this PR fixes it.

This is a bug fix. Before this PR, the proxy raised a recoverable error even when invalid values are passed.

PR review check list

Quality check list that cannot be automatically verified.

  • Safety
  • Code quality
    • Error conditions are handled
    • Exceptions are propagated to the correct parent greenlet
    • Exceptions are correctly classified as recoverable or unrecoverable
  • Compatibility
    • State changes are forward compatible
    • Transport messages are backwards and forward compatible
  • Commits
    • Have good messages
    • Squashed unecessary commits
  • If it's a bug fix:
    • Regression test for the bug
      • Properly covers the bug
      • If an integration test is used, it could not be written as a unit test
  • Documentation
    • A new CLI flag was introduced, is there documentation that explains usage?
  • Specs
    • If this is a protocol change, are the specs updated accordingly? If so, please link PR from the specs repo.
  • Is it a user facing feature/bug fix?
    • Changelog entry has been added

@auto-assign auto-assign Bot requested a review from karlb September 23, 2019 14:37
@pirapira pirapira mentioned this pull request Sep 23, 2019
13 tasks
@pirapira pirapira force-pushed the broken-precondition-passed branch 2 times, most recently from 60f7c26 to eba97be Compare September 23, 2019 14:40
Copy link
Copy Markdown
Contributor

@karlb karlb left a comment

Choose a reason for hiding this comment

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

@rakanalh In #4936 (comment) you said that these should not be BrokenPreconditionErrors. Have you been convinced? It looks sensible to me.

Comment thread raiden/exceptions.py
""" Raised if the token does not follow the ERC20 standard """


class InvalidTokenAddress(RaidenError):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of removing these, you could make InvalidTokenAddress a subclass of BrokenPreconditionError. Fine grained exceptions are usually a nice thing, e.g. you could mark wrong input fields in the UI or add error codes to exceptions and pass them to API users.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Copy Markdown
Contributor Author

@pirapira pirapira Sep 23, 2019

Choose a reason for hiding this comment

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

No, I'm not sure. When the API raises these exceptions, that should not crash the node.

Also I've seen that the proxy should not raise specific errors #4878 (comment). I'm seeing another contradiction here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@rakanalh, in the end, are proxies allowed to raise specific errors? If yes, in which circumstances? I'll document and follow what you say.

@pirapira
Copy link
Copy Markdown
Contributor Author

@rakanalh said these should not be BrokenPreconditionError. When I read the docstring of BrokenPreconditionError, it says something like ValueError should be BrokenPreconditionError. So I'm seeing a contradiction there.

because the caller of the proxy should have checked these inputs.

The documentation for BrokenPreconditionError clearly says
```
class BrokenPreconditionError(RaidenError):
    """ Raised while checking transaction preconditions
    which should be satisfied before sending the transaction.
    This exception when:
    1. An assert or a revert in the smart contract would be hit for
    triggering block.

    2. If provided values are invalid (i.e ValueError)
    """
```

So, when the provided values are invalid, BrokenPreconditionError
should be raised.
@pirapira
Copy link
Copy Markdown
Contributor Author

On the second point, we agreed that the BrokenPreconditionError is for blockchain checks.

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