Skip to content

Commit

Permalink
Merge pull request #38 from RegioHelden/fix-substitute-error-msg
Browse files Browse the repository at this point in the history
Fix substitute error msg
  • Loading branch information
bodja authored Nov 18, 2024
2 parents 1559c3c + 4b3382b commit 8c20b01
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.bumpversion]
current_version = "0.5.6"
current_version = "0.5.7"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
search = "{current_version}"
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.5.7 (2024-11-18)
* `@substitute_error` now shows error message of the original error.

## 0.5.6 (2024-11-13)
* Fix `DjangoKafka.run_consumers` failing when there are no consumers in the registry.

Expand Down
2 changes: 1 addition & 1 deletion django_kafka/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

logger = logging.getLogger(__name__)

__version__ = "0.5.6"
__version__ = "0.5.7"

__all__ = [
"autodiscover",
Expand Down
2 changes: 1 addition & 1 deletion django_kafka/management/commands/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except tuple(errors) as original_error:
raise substitution from original_error
raise substitution(original_error) from original_error
return wrapper
return decorator
16 changes: 10 additions & 6 deletions django_kafka/tests/connect/test_substitute_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@

class SubstituteErrorTestCase(SimpleTestCase):
def test_substitute(self):
class CustomException(Exception):
class CustomError(Exception):
pass

errors = [ValueError, KeyError, CustomException]
decorator = substitute_error(errors, CommandError)
errors = {
ValueError: "value error",
KeyError: "key error",
CustomError: "custom error",
}
decorator = substitute_error(errors.keys(), CommandError)

for error in errors:
func = Mock(side_effect=error)
for error, msg in errors.items():
func = Mock(side_effect=error(msg))

with self.assertRaises(CommandError):
with self.assertRaisesMessage(CommandError, msg):
decorator(func)()
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 = "django-kafka"
version = "0.5.6"
version = "0.5.7"
dependencies = [
"django>=4.0,<6.0",
"confluent-kafka[avro, schema-registry]==2.4.0"
Expand Down

0 comments on commit 8c20b01

Please sign in to comment.