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

add: custom message for plugin errors #613

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion core/cat/mad_hatter/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from cat.mad_hatter.decorators import CatTool, CatHook, CatPluginOverride
from cat.utils import to_camel_case
from cat.log import log

from cat import utils

# Empty class to represent basic plugin Settings model
class PluginSettingsModel(BaseModel):
Expand Down Expand Up @@ -131,6 +131,8 @@ def load_settings(self):
except Exception as e:
log.error(f"Unable to load plugin {self._id} settings")
log.error(e)
log.warning(utils.plugin_specific_error_message(self.manifest["name"], self.manifest["plugin_url"]))
traceback.print_exc()
raise e
# settings.json does not exist # TODO: may be buggy or there is a better way via json_schema
#else:
Expand Down Expand Up @@ -166,6 +168,8 @@ def save_settings(self, settings: Dict):
json.dump(updated_settings, json_file, indent=4)
except Exception:
log.error(f"Unable to save plugin {self._id} settings")
log.warning(utils.plugin_specific_error_message(self.manifest["name"], self.manifest["plugin_url"]))
traceback.print_exc()
return {}

return updated_settings
Expand Down Expand Up @@ -226,6 +230,7 @@ def _load_decorated_functions(self):
plugin_overrides += getmembers(plugin_module, self._is_cat_plugin_override)
except Exception as e:
log.error(f"Error in {py_filename}: {str(e)}")
log.warning(utils.plugin_specific_error_message(self.manifest["name"], self.manifest["plugin_url"]))
traceback.print_exc()
raise Exception(f"Unable to load the plugin {self._id}")

Expand Down
3 changes: 3 additions & 0 deletions core/cat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def explicit_error_message(e):

return error_description

def plugin_specific_error_message(name, url):
return """To resolve any problem related to {} plugin,
contact the creator using github issue at the link {}""".format(name, url)

# This is our masterwork during tea time
class singleton:
Expand Down
Loading