Commit Graph

46 Commits

Author SHA1 Message Date
Jacek Sieka 5ebd771d35
per-function `Exception` handling (#457)
This PR replaces the global strict exception mode with an option to
handle `Exception` per function while at the same time enabling strict
exception checking globally by default as has been planned for v4.

`handleException` mode raises `AsyncExceptionError` to distinguish it
from `ValueError` which may originate from user code.

* remove obsolete 1.2 config options
2023-11-08 15:12:32 +01:00
Jacek Sieka cd6369c048
`asyncraises` -> `async: (raises: ..., raw: ...)` (#455)
Per discussion in
https://github.com/status-im/nim-chronos/pull/251#issuecomment-1559233139,
`async: (parameters..)` is introduced as a way to customize the async
transformation instead of relying on separate keywords (like
asyncraises).

Two parameters are available as of now:

`raises`: controls the exception effect tracking
`raw`: disables body transformation

Parameters are added to `async` as a tuple allowing more params to be
added easily in the future:
```nim:
proc f() {.async: (name: value, ...).}`
```
2023-11-07 12:12:59 +02:00
Tanguy 12dc36cfee
Update README regarding cancellation (#450)
* Update README regarding cancellation

* Apply suggestions from code review

Co-authored-by: Eugene Kabanov <eugene.kabanov@status.im>

---------

Co-authored-by: Jacek Sieka <jacek@status.im>
Co-authored-by: Eugene Kabanov <eugene.kabanov@status.im>
2023-10-25 15:16:10 +02:00
Jacek Sieka f56d286687
introduce `asyncraises` to core future utilities (#454)
* introduce `asyncraises` to core future utilities

Similar to the introduction of `raises` into a codebase, `asyncraises`
needs to be introduced gradually across all functionality before
deriving benefit.

This is a first introduction along with utilities to manage raises lists
and transform them at compile time.

Several scenarios ensue:

* for trivial cases, adding `asyncraises` is enough and the framework
deduces the rest
* some functions "add" new asyncraises (similar to what `raise` does in
"normal" code) - for example `wait` may raise all exceptions of the
future passed to it and additionally a few of its own - this requires
extending the raises list
* som functions "remove" raises (similar to what `try/except` does) such
as `nocancel` with blocks cancellations and therefore reduce the raising
set

Both of the above cases are currently handled by a macro, but depending
on the situation lead to code organisation issues around return types
and pragma limitations - in particular, to keep `asyncraises`
backwards-compatibility, some code needs to exist in two versions which
somewhat complicates the implementation.

* add `asyncraises` versions for several `asyncfutures` utilities
* when assigning exceptions to a `Future` via `fail`, check at compile
time if possible and at runtime if not that the exception matches
constraints
* fix `waitFor` comments
* move async raises to separate module, implement `or`
2023-10-24 16:21:07 +02:00
Tanguy a759c11ce4
Raise tracking (#251)
* Exception tracking v2

* some fixes

* Nim 1.2 compat

* simpler things

* Fixes for libp2p

* Fixes for strictException

* better await exception check

* Fix for template async proc

* make async work with procTy

* FuturEx is now a ref object type

* add tests

* update test

* update readme

* Switch to asyncraises pragma

* Address tests review comments

* Rename FuturEx to RaiseTrackingFuture

* Fix typo

* Split asyncraises into async, asyncraises

* Add -d:chronosWarnMissingRaises

* Add comment to RaiseTrackingFuture

* Allow standalone asyncraises

* CheckedFuture.fail type checking

* First cleanup

* Remove useless line

* Review comments

* nimble: Remove #head from unittest2

* Remove implict raises: CancelledError

* Move checkFutureExceptions to asyncfutures2

* Small refacto

* small cleanup

* Complete in closure finally

* cleanup tests, add comment

* bump

* chronos is not compatible with nim 1.2 anymore

* re-add readme modifications

* fix special exception handlers

* also propagate excetion type in `read`

* `RaiseTrackingFuture` -> `InternalRaisesFuture`

Use internal naming scheme for RTF (this type should only be accessed
via asyncraises)

* use `internalError` for error reading

* oops

* 2.0 workarounds

* again

* remove try/finally for non-raising functions

* Revert "remove try/finally for non-raising functions"

This reverts commit 86bfeb5c972ef379a3bd34e4a16cd158a7455721.

`finally` is needed if code returns early :/

* fixes

* avoid exposing `newInternalRaisesFuture` in manual macro code
* avoid unnecessary codegen for `Future[void]`
* avoid reduntant block around async proc body
* simplify body generation for forward declarations with comment but no
body
* avoid duplicate `gcsafe` annotiations
* line info for return at end of async proc

* expand tests

* fix comments, add defer test

---------

Co-authored-by: Jacek Sieka <jacek@status.im>
2023-10-17 14:18:14 +02:00
cheatfate db6410f835
Fix CI badge status. 2023-09-05 13:48:09 +03:00
Jacek Sieka 229de5f842
Compile-time configuration (#371)
This PR moves all compile-time configuration to a single module,
simplifying documentation and access to these features.

Upcomfing features may be enabled either individually, or through a new
`chronosPreviewV4` catch-all designed to allow code to be prepared for
increased strictness in future chronos releases.

`-d:chronosDebug` may be used to enable the existing debugging helpers
together.
2023-03-31 07:35:04 +02:00
Tanguy a50ac4f642
Documentation (#311)
* Fix & update asyncloop documentation

* Add cancellation documentation

* Add documentation generation workflow

* pin nim version for doc gen

* update readme

* fix example

* Simplify examples
2023-02-16 21:27:31 +01:00
Jacek Sieka 396ed554f6
Update README.md 2022-09-06 18:50:12 +02:00
Jacek Sieka 8ce9f54bb7
Document `-d:asyncBackend` (fixes #207) (#216) 2021-11-08 15:17:37 +01:00
Pietro Peterlongo a46cc59627
fix web framework name Looper -> Scorper (#189)
apparently it has changed name
2021-05-27 10:53:11 +02:00
Jacek Sieka 4abd7a5645
exception tracking (#166)
* exception tracking

This PR adds minimal exception tracking to chronos, moving the goalpost
one step further.

In particular, it becomes invalid to raise exceptions from `callSoon`
callbacks: this is critical for writing correct error handling because
there's no reasonable way that a user of chronos can possibly _reason_
about exceptions coming out of there: the event loop will be in an
indeterminite state when the loop is executing an _random_ callback.

As expected, there are several issues in the error handling of chronos:
in particular, it will end up in an inconsistent internal state whenever
the selector loop operations fail, because the internal state update
functions are not written in an exception-safe way. This PR turns this
into a Defect, which probably is not the optimal way of handling things
- expect more work to be done here.

Some API have no way of reporting back errors to callers - for example,
when something fails in the accept loop, there's not much it can do, and
no way to report it back to the user of the API - this has been fixed
with the new accept flow - the old one should be deprecated.

Finally, there is information loss in the API: in composite operations
like `poll` and `waitFor` there's no way to differentiate internal
errors from user-level errors originating from callbacks.

* store `CatchableError` in future
* annotate proc's with correct raises information
* `selectors2` to avoid non-CatchableError IOSelectorsException
* `$` should never raise
* remove unnecessary gcsafe annotations
* fix exceptions leaking out of timer waits
* fix some imports
* functions must signal raising the union of all exceptions across all
platforms to enable cross-platform code
* switch to unittest2
* add `selectors2` which supercedes the std library version and fixes
several exception handling issues in there

* fixes

* docs, platform-independent eh specifiers for some functions

* add feature flag for strict exception mode

also bump version to 3.0.0 - _most_ existing code should be compatible
with this version of exception handling but some things might need
fixing - callbacks, existing raises specifications etc.

* fix AsyncCheck for non-void T
2021-03-24 10:08:33 +01:00
Jacek Sieka b964ba2966
Update README (#167) 2021-03-20 08:12:35 +01:00
cheatfate 03707426e4
Remove Travis CI badge and move Github Actions badge. 2021-02-28 00:12:49 +02:00
Ștefan Talpalaru 39456e9c18
README: remove claim about temp var reordering (#155)
...between `await` calls. Can no longer replicate.
2021-02-10 16:49:12 +02:00
andri lim c1f6e7276e
add github action script (#144) 2021-01-20 17:36:10 +02:00
Zahary Karadjov 826d48c4aa Revert "more docs (#111)"
This reverts commit d0a17d551f.

Moving CancelledError outside of the established Nim hierarchy is
not a solution that has rough consensus and has an unknown impact
on compatibility with otherwise correctly implemented cancellation
code (for example when `CatchableError` is caught, cleanup is done,
then the exception is reraised). Further, this breaks the established
convention in the Nim community that Exception should not be inherited
from, complicating compatibility with future Nim versions that may
enforce this more strongly.
2020-08-16 01:48:25 +03:00
Zahary Karadjov 03f4a26829 Revert "yieldAsync() (#120)"
This reverts commit 284d677815.

There is no rough consensus for how this should be implemented and
whether it's needed indeed - a use case that cannot be solved with
a queue or a lock/event should be identified before pursuing this
functionality.
2020-08-16 01:48:25 +03:00
Ștefan Talpalaru 284d677815
yieldAsync() (#120) 2020-08-10 15:31:21 +02:00
Ștefan Talpalaru d0a17d551f
more docs (#111)
* more docs

* make CancelledError and object of Exception
2020-08-06 20:52:50 +02:00
Ștefan Talpalaru 63041b2d8f
start documenting the library (#109)
* start documenting the library

* introduce futures

* running the event loop

* async procs and "await"

* more "await" examples

* clarify internal callback creation

* error handling

* address review comments

* remove TODO item

* more about future completion
2020-07-13 17:59:11 +02:00
Jacek Sieka 4cc1b42108
Remove ad comparison from front page 2019-08-06 12:49:45 +02:00
Bruno Škvorc 62da8212a4
Updated README to match nimbus-launch template 2019-05-20 17:43:23 +02:00
Mamy Ratsimbazafy 79376dab20
Appveyor doesn't rename projects properly 2019-02-06 18:03:15 +01:00
cheatfate 4b084f276d Fix badges. 2019-02-06 18:57:33 +02:00
Jacek Sieka 47b19a55fd
Update README.md 2019-02-06 16:43:27 +01:00
Mamy Ratsimbazafy 9f15c6b752
Rebrand Asyncdispatch2 to Chronos [WIP] (#20)
* Update file headers, copyright date

* Rename files and hopefully fix nimble

* Forgot to change path in tests

* Update readme
2019-02-06 15:49:11 +01:00
Bruno Škvorc 90f2a50dda
Update README.md 2019-01-02 14:53:00 +01:00
Jacek Sieka 00d7d49ef1
readme: update license 2018-09-05 12:45:22 -06:00
Jacek Sieka e53c8d0f4e
update readme 2018-09-04 21:36:14 -06:00
Jacek Sieka 9d2222596d
update readme 2018-09-04 21:27:01 -06:00
cheatfate 98a85c5614 Fix #7. 2018-08-18 00:25:34 +03:00
cheatfate 50a91cef9f Update licenses badges. 2018-06-19 02:08:55 +03:00
alexm-status 3e0cc658b0
Update README.md 2018-05-30 14:27:08 -07:00
cheatfate 490f8484ca Update README. 2018-05-30 06:35:58 +03:00
cheatfate 4f670ac7e8 Update documentation in README. 2018-05-30 06:34:58 +03:00
cheatfate ebbb5b73ef Updated README. 2018-05-30 06:32:47 +03:00
alexm-status 645108813f
Update README.md 2018-05-29 09:49:05 -07:00
alexm-status e823a52db4
Copy-edited README 2018-05-29 09:24:34 -07:00
cheatfate e33ed13fb5 Updated README. 2018-05-29 02:45:15 +03:00
cheatfate 3c7273d532 Update README. 2018-05-29 02:38:53 +03:00
cheatfate edcc628b30 Update README. 2018-05-29 02:37:06 +03:00
cheatfate 5529fc4669 Updated README.
Updated documentation.
2018-05-29 02:35:15 +03:00
Your Name ab91baff47 Add AppVeyor badge. 2018-05-22 01:15:34 +03:00
Your Name 52bf688179 Add Travis badge, and trigger first test. 2018-05-22 01:04:49 +03:00
Eugene Kabanov 28ae5ff057
Initial commit 2018-05-16 11:18:44 +03:00