Skip to content

Feature/improve error traceability when instantiation fails#7

Merged
marcoshj merged 5 commits intomasterfrom
feature/improve_error_traceability_when_instantiation_fails
Jan 27, 2020
Merged

Feature/improve error traceability when instantiation fails#7
marcoshj merged 5 commits intomasterfrom
feature/improve_error_traceability_when_instantiation_fails

Conversation

@marcoshj
Copy link
Contributor

@marcoshj marcoshj commented Jan 27, 2020

Description

When a service is being instantiated, if the definition is incomplete or incorrect, the container would raise a generic TypeError, with a huge traceback.

With this change, the traceback shows more information about the error:

Traceback (most recent call last):
  File "/usr/src/app/src/pypendency/container.py", line 98, in __instance_from_fqn
    return klass(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'failing_param'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/src/app/src/pypendency/container.py", line 57, in get
    return self._do_get(identifier)
  File "/usr/src/app/src/pypendency/container.py", line 80, in _do_get
    instance = self.__instance_from_fqn(definition.fully_qualified_name, args, kwargs)
  File "/usr/src/app/src/pypendency/container.py", line 100, in __instance_from_fqn
    raise ServiceNotInstantiable(fully_qualified_name) from e
pypendency.container.ServiceNotInstantiable: Service tests.resources.class_c.C cannot be instantiated by the container

How to test

  • Create a definition for a class with more parameters than expected. Ask for it to the container, should raise this ServiceNotInstantiable exception, with a readable traceback.
  • Same test, but in this case, with less parameters than expected. We expect the same result.
  • The container should keep working as usual. Try get a service from a valid definition. It should work

@marcoshj marcoshj requested a review from lpl January 27, 2020 10:31
@marcoshj marcoshj self-assigned this Jan 27, 2020
Copy link
Contributor

@lpl lpl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected!

  • Missing args
    image

  • More args
    image

@lpl
Copy link
Contributor

lpl commented Jan 27, 2020

Testing done to release new production ready version:

  • Change previous PythonLoader.load() by PythonLoader.load_by_module_name().
  • Change PythonLoader.load_by_module_name() by new PythonLoader.load() using absolute paths.
  • Test that all declared dependencies can be resolved.
  • Test non absolute path services declaration fail.
  • Test wrong declared service cannot be instantiated.
  • Test python load dir works.
  • Test yaml load dir works.

@marcoshj marcoshj merged commit 95b7e83 into master Jan 27, 2020
@marcoshj marcoshj deleted the feature/improve_error_traceability_when_instantiation_fails branch January 27, 2020 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments