Skip to content

Commit

Permalink
Merge pull request #24 from pomponchik/develop
Browse files Browse the repository at this point in the history
0.0.19
  • Loading branch information
pomponchik authored Feb 17, 2024
2 parents 318dfbd + 41d5679 commit 666aad4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cantok/tokens/condition_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ def get_extra_kwargs(self) -> Dict[str, Any]:
}

def get_superpower_exception_message(self) -> str:
return 'The condition is not met.'
return 'The cancellation condition was satisfied.'
30 changes: 29 additions & 1 deletion docs/docs/what_are_tokens/exceptions.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
Each token class has its own exception and it can be found in the `exception` attribute of the class:
When a token is canceled, you can call the `check()` method from it and an exception will be raised:

```python
from cantok import TimeoutToken

token = TimeoutToken(1)
token.wait()
token.check()
# cantok.errors.TimeoutCancellationError: The timeout of 1 seconds has expired.
```

Each type of token has a corresponding type of exception that can be raised in this case:

```
SimpleToken -> CancellationError
ConditionToken -> ConditionCancellationError
TimeoutToken -> TimeoutCancellationError
CounterToken -> CounterCancellationError
```

When you call the `check()` method on any token, one of two things will happen. If it (or any of the tokens nested in it) was canceled by calling the `cancel()` method, `CancellationError` will always be raised. But if the cancellation occurred as a result of the unique ability of the token, such as for `TimeoutToken` - timeout expiration, then an exception specific to this type of token will be raised.

You can import each of these exceptions from the library directly:

```python
from cantok import CancellationError, ConditionCancellationError, TimeoutCancellationError, CounterCancellationError
```

Also each token class has its own exception and it can be found in the `exception` attribute of the class:

```python
from cantok import TimeoutToken, CancellationError
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "cantok"
version = "0.0.18"
version = "0.0.19"
authors = [
{ name="Evgeniy Blinov", email="zheni-b@yandex.ru" },
]
Expand Down
4 changes: 2 additions & 2 deletions tests/units/tokens/test_condition_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_check_superpower_raised():
try:
token.check()
except ConditionCancellationError as e:
assert str(e) == 'The condition is not met.'
assert str(e) == 'The cancellation condition was satisfied.'
assert e.token is token


Expand All @@ -164,7 +164,7 @@ def test_check_superpower_raised_nested():
try:
token.check()
except ConditionCancellationError as e:
assert str(e) == 'The condition is not met.'
assert str(e) == 'The cancellation condition was satisfied.'
assert e.token is nested_token
assert e.token.exception is type(e)

Expand Down

0 comments on commit 666aad4

Please sign in to comment.