Skip to content

Commit

Permalink
Improve UnknownQualifiedServiceRequestedError message
Browse files Browse the repository at this point in the history
  • Loading branch information
maldoinc committed Aug 25, 2024
1 parent cb08a41 commit 219c021
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions test/unit/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def inner(_sub1: FooBase = Inject(qualifier="sub1")): ...

self.assertIn(
"Cannot instantiate concrete class for <class 'test.fixtures.FooBase'> "
"as qualifier 'sub1' is unknown. Available qualifiers: set()",
"as qualifier 'sub1' is unknown. Available qualifiers: []",
str(context.exception),
)

Expand All @@ -315,7 +315,7 @@ def inner(_sub1: FooBase): ...

self.assertEqual(
f"Cannot instantiate concrete class for {FooBase} as qualifier 'None' is unknown. "
"Available qualifiers: {'foobar'}",
"Available qualifiers: ['foobar'].",
str(context.exception),
)

Expand All @@ -329,7 +329,7 @@ def inner(_sub1: FooBase): ...

self.assertEqual(
f"Cannot instantiate concrete class for {FooBase} as qualifier 'None' is unknown. "
"Available qualifiers: set()",
"Available qualifiers: [].",
str(context.exception),
)

Expand All @@ -345,7 +345,7 @@ def inner(_foo: RegisterWithQualifierClass): ...

self.assertIn(
f"Cannot instantiate concrete class for {RegisterWithQualifierClass} "
f"as qualifier 'None' is unknown. Available qualifiers: {{'{__name__}'}}",
f"as qualifier 'None' is unknown. Available qualifiers: ['{__name__}'].",
str(context.exception),
)

Expand Down
3 changes: 2 additions & 1 deletion wireup/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ def __init__(
) -> None:
self.klass = klass
self.qualifier = qualifier
qualifiers_str = ", ".join(sorted(f"'{q}'" for q in available_qualifiers))

super().__init__(
f"Cannot instantiate concrete class for {klass} as qualifier '{qualifier}' is unknown. "
f"Available qualifiers: {available_qualifiers}",
f"Available qualifiers: [{qualifiers_str}].",
)


Expand Down

0 comments on commit 219c021

Please sign in to comment.