Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion: More helpful error messages for failed AdaptationOffer contributions #425

Open
stpotter16 opened this issue Jun 14, 2021 · 2 comments

Comments

@stpotter16
Copy link

stpotter16 commented Jun 14, 2021

Preface: The following discussion/"request" could easily be chalked up to "Just be more careful" so feel free to close and move on.

That said, the following code

  contributed_adaptation_offers = List(
        contributes_to=ADAPTATION_OFFERS
    )

    def _contributed_adaptation_offers_default(self):
        return [
            AdaptationOffer(
                factory=...,
                from_protocol=...,
                to_protocl=...,
            )
        ]

created this traceback:

--- Logging error ---
Traceback (most recent call last):
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/logging/__init__.py", line 994, in emit
    msg = self.format(record)
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/logging/__init__.py", line 840, in format
    return fmt.format(record)
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/logging/__init__.py", line 577, in format
    record.message = record.getMessage()
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/logging/__init__.py", line 338, in getMessage
    msg = msg % self.args
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/traits/adaptation/adaptation_offer.py", line 31, in __repr__
    return (f"<{self.__class__.__name__}: '{self.from_protocol_name}' "
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/traits/adaptation/adaptation_offer.py", line 69, in _get_to_protocol_name
    return self._get_type_name(self._to_protocol)
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/traits/adaptation/adaptation_offer.py", line 150, in _get_type_name
    module=type_or_type_name.__module__,
AttributeError: 'NoneType' object has no attribute '__module__'
Call stack:
...
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/ui/tasks/tasks_application.py", line 356, in _create_windows
    window = self.create_window(window_layout, restore=True)
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/ui/tasks/tasks_application.py", line 257, in create_window
    task = self.create_task(task_id)
...
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/ui/tasks/tasks_application.py", line 206, in create_task
    for ext in self.task_extensions
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/extension_point.py", line 169, in get
    extensions = extension_registry.get_extensions(self.id)
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/extension_registry.py", line 114, in get_extensions
    return self._get_extensions(extension_point_id)[:]
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/provider_extension_registry.py", line 103, in _get_extensions
    extensions = self._initialize_extensions(extension_point_id)
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/provider_extension_registry.py", line 289, in _initialize_extensions
    extensions.append(provider.get_extensions(extension_point_id)[:])
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/plugin.py", line 156, in get_extensions
    extensions = self._get_extensions_from_trait(trait_names[0])
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/plugin.py", line 355, in _get_extensions_from_trait
    extensions = getattr(self, trait_name)
...
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/application.py", line 383, in get_service
    protocol, query, minimize, maximize
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/service_registry.py", line 87, in get_service
    services = self.get_services(protocol, query, minimize, maximize)
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/service_registry.py", line 124, in get_services
    actual_protocol, name, obj, properties, service_id
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/service_registry.py", line 269, in _resolve_factory
    obj = obj(**properties)
...
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/extension_point.py", line 169, in get
    extensions = extension_registry.get_extensions(self.id)
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/application.py", line 213, in get_extensions
    return self.extension_registry.get_extensions(extension_point_id)
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/extension_registry.py", line 114, in get_extensions
    return self._get_extensions(extension_point_id)[:]
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/provider_extension_registry.py", line 103, in _get_extensions
    extensions = self._initialize_extensions(extension_point_id)
  File "/home/spotter/.edm/envs/seismic36/lib/python3.6/site-packages/envisage/provider_extension_registry.py", line 291, in _initialize_extensions
    logger.debug("extensions to <%s> <%s>", extension_point_id, extensions)
Unable to print the message and arguments - possible formatting error.
Use the traceback above to help find the error.

No peaking, see if you can spot the error (again it's a case of "Be more careful")

Answer
 
diff --git a/steelhead/plugin/steelhead_plugin.py b/steelhead/plugin/steelhead_plugin.py
index 2a4e533a..75a26646 100644
--- a/steelhead/plugin/steelhead_plugin.py
+++ b/steelhead/plugin/steelhead_plugin.py
@@ -50,6 +50,6 @@ class ZgyPlugin(Plugin):
             AdaptationOffer(
                 factory=ZgyVolumeToISeismicVolume,
                 from_protocol=ZgyVolume,
-                to_protocl=I_SEISMIC_VOLUME,
+                to_protocol=I_SEISMIC_VOLUME,
             )
         ]

So my low priority request is a more useful error message here or more careful parsing of the contents passed into the constructor of AdaptationOffer

@rahulporuri
Copy link
Contributor

This probably belongs in traits - the error, as I understand it, is because AdaptationOffer is a HasTraits and not a HasStrictTraits or a HasRequiredTraits. We should also probably prevent to_protocol and the other related traits not accept None.

Ref https://github.com/enthought/traits/blob/9fbd3fb8f72bf2d2e37675bf5dc6e3983dd1c4a5/traits/adaptation/adaptation_offer.py.

@stpotter16 what do you think?

@stpotter16
Copy link
Author

@rahulporuri Good points. I'm okay to move this over to traits, just wanted to log my experience in a publicly visible place.

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

No branches or pull requests

2 participants