-
Notifications
You must be signed in to change notification settings - Fork 56
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
Raises #547
Conversation
* extracting dialing logic to dialer * exposing upgrade methods on transport * cleanup * fixing tests to use new interfaces * add comments
I'm not sure how to make nim pick the correct version of chronos when using the branch name, it seems to ignore the branch in the nimble file and just pick whatever looks like the latest numeric version so CI is broken for now. But it works in the nimbus repo if the proper branches in chronos ( |
Fixes #525 add coverage to unsubscribeAll and testing
It might make the transition more smooth if the refactoring to raise a single exception type was separated from the chronos exception adaptation.
it is using the correct chronos branch - the error is legit, you need to annotate all |
It's not, it's picking the wrong chronos and this is verifiable by
This is well understood and it is what the branch is attempting to do. However, since |
no idea what |
libp2p/stream/connection.nim
Outdated
@@ -53,7 +56,8 @@ proc onUpgrade*(s: Connection) {.async.} = | |||
if not isNil(s.upgraded): | |||
await s.upgraded | |||
|
|||
func shortLog*(conn: Connection): string = | |||
func shortLog*(conn: Connection): string | |||
{.raises: [Defect, ValueError].} = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shortLog
should never raise - in fact it doesn't actually except that &
raises on invalid format strings - the right thing to do here is to catch the ValueError
and turn it into a Defect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, quick and dirty fix to get things to compile on first pass, but I suspected that this wasn't the right approach.
|
c.connEvents.mgetOrPut(kind, | ||
initOrderedSet[ConnEventHandler]()).incl(handler) | ||
except Exception as exc: | ||
# TODO: there is an Exception being raised |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is probably nim-lang/Nim#17382 - looks like a nim bug, can use it in the comment to highlight where it happens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, it incorrectly raises whatever handler
raises - since you saw Exception
here it means handler
itself was missing a correct raises signature - looks like it has one now though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConnEventHandler
is defined as:
ConnEventHandler* =
proc(peerId: PeerID, event: ConnEvent): Future[void]
{.gcsafe, raises: [Defect].}
But interestingly, it seems to ignore that when actually declaring the handler which is in https://github.com/status-im/nim-libp2p/blob/unstable/tests/testswitch.nim#L249. Another bug?
Did you run it with the instructions I left in #547 (comment)? |
looks like there's a copy of |
There is a |
Yes, I ran into the issue with unhandled |
no, it only applies to |
yes, but that doesn't mean it works the same with unit tests and nimble etc - the eh tracking issues issues sometimes seem to depend on the order in which the compiler sees the code which might be different depending on include path order etc - it's easiest to just annotate everything consistently |
Seems to work for |
Actually, I took another look at this and I think that this PR should generally work as expected. Here is an example of an expanded async proc: proc readExactly*(s: LPStream; pbytes: pointer; nbytes: int): Future[void] {.
raises: [Defect, LPStreamEOFError, LPStreamIncompleteError], stackTrace: off.} =
var chronosInternalRetFuture = newFuture[void]("readExactly")
iterator readExactly_65120132(): FutureBase {.closure,
raises: [Defect, CatchableError].} =
block:
template result(): auto {.used.} =
{.fatal: "You should not reference the `result` variable inside a void async proc".}
if s.atEof:
raise newLPStreamEOFError()
...
Any proc called by the iterator can raise an exception of type |
As I said on discord, I think only the inner iterator matters in fact, and that is the root of the issue. |
To understand why the annotation is wrong, you need to read the whole transformed function: proc readExactly*(rstream: AsyncStreamReader; pbytes: pointer; nbytes: int): Future[
void] {.stackTrace: off.} =
var chronosInternalRetFuture = newFuture[void]("readExactly")
iterator readExactly_25840371(): FutureBase {.closure,
raises: [Defect, CatchableError, Exception].} =
block:
template result(): auto {.used.} =
{.fatal: "You should not reference the `result` variable inside a void async proc".}
...
complete(chronosInternalRetFuture)
var nameIterVar`gensym25840373 = readExactly_25840371
{.push, stackTrace: off.}
var readExactly_continue_25840372: proc (udata`gensym25840374: pointer) {.gcsafe,
raises: [Defect].}
readExactly_continue_25840372 = proc (udata`gensym25840375: pointer) {.gcsafe,
raises: [Defect].} =
try:
if not (nameIterVar`gensym25840373.finished()):
var next`gensym25840376 = nameIterVar`gensym25840373()
while (not next`gensym25840376.isNil()) and
next`gensym25840376.finished():
next`gensym25840376 = nameIterVar`gensym25840373()
if nameIterVar`gensym25840373.finished():
break
if next`gensym25840376 == nil:
if not (chronosInternalRetFuture.finished()):
const
msg`gensym25840377 = "Async procedure (&" & "readExactly" &
") yielded `nil`, " &
"are you await\'ing a `nil` Future?"
raiseAssert msg`gensym25840377
else:
next`gensym25840376.addCallback(readExactly_continue_25840372)
except CancelledError:
chronosInternalRetFuture.cancelAndSchedule()
except CatchableError as exc`gensym25840378:
chronosInternalRetFuture.fail(exc`gensym25840378)
except Exception as exc`gensym25840379:
if exc`gensym25840379 of Defect:
raise (ref Defect)(exc`gensym25840379)
chronosInternalRetFuture.fail((ref ValueError)(msg: exc`gensym25840379.msg,
parent: exc`gensym25840379))
readExactly_continue_25840372(nil)
{.pop.}
return chronosInternalRetFuture In particular, you need to understand that the transformed If you read on, you will notice that By adding the annotation, you're creating a lie that will impact code down the line, because |
this is the path forward right now that causes the least issues for future code - it would be good to put the code in a cleaned up branch so we can remove the hacks from nbc as well - a new PR is probably appropriate because there's a lot of comments in this branch that come from pre-release versions of chronos 3. |
39645a8
to
5419784
Compare
Obsoleted by #1050 et al. |
First attempt to use
raises
inasync
procs, uses status-im/nim-chronos#166.