vacp2p / nim-libp2p

libp2p implementation in Nim
https://vacp2p.github.io/nim-libp2p/docs/
MIT License
242 stars 52 forks source link

avoid pointless exception raising in `dcutr/server` #1063

Closed etan-status closed 3 months ago

etan-status commented 3 months ago

dcutr/server is the only protocol handler outside tests / examples that raises exceptions. The only caller of this handler is defined in MultStreamSelect.handle, which has a surrounding except block that catches CatchableError.

When the handler raises a non-CancelledError the flow is:

  1. await protocolHolder.protocol.handler(conn, ms)
  2. The finally block after it
  3. The return, both in successful and in exception case
  4. The outer except CatchableError as exc:, it logs and discards exc
  5. The outer finally: await conn.close()
  6. Stopped multistream handler log, both in successful and exc case.

By changing dcutr/server to only log but not also raise, difference is that the outer except CatchableError in step (4) is skipped.

As that is a redundant log anyway (dcutr/server already logs), it should be fine to not raise. That's in line with all the other protocol handlers (besides tests / examples) and opens up limiting {.raises.} annotation for handlers to just [CancelledError].

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 50.00000% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 82.57%. Comparing base (08a48fa) to head (869d199).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1063/graphs/tree.svg?width=650&height=150&src=pr&token=UR5JRQ249W&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im)](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1063?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im) ```diff @@ Coverage Diff @@ ## unstable #1063 +/- ## ========================================= Coverage 82.56% 82.57% ========================================= Files 91 91 Lines 15814 15812 -2 ========================================= - Hits 13057 13056 -1 + Misses 2757 2756 -1 ``` | [Files](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1063?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im) | Coverage Δ | | |---|---|---| | [libp2p/protocols/connectivity/dcutr/server.nim](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1063?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im#diff-bGlicDJwL3Byb3RvY29scy9jb25uZWN0aXZpdHkvZGN1dHIvc2VydmVyLm5pbQ==) | `80.00% <50.00%> (-0.86%)` | :arrow_down: | ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1063/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im)