Skip to content

refact(zopeutil): Made error msg more descriptive#486

Merged
drfho merged 3 commits intomainfrom
zopeutil-more-descriptive-error-msg
May 7, 2026
Merged

refact(zopeutil): Made error msg more descriptive#486
drfho merged 3 commits intomainfrom
zopeutil-more-descriptive-error-msg

Conversation

@cmeier76
Copy link
Copy Markdown
Member

@cmeier76 cmeier76 commented May 6, 2026

This PR tries to improve the feedback in ZMI if errors occur in custom code. It replaces the internal representation <Products.zms.zopeutil.MissingArtefactProxy object at 0x113a57890> by a more descriptive error messages for broken ExternalMethods in ZMSMetaobjManager.

I cannot fully assess the impact of changing the try/except-handling in zopeutil, as I do not understand the previous changes referenced below. Furthermore, other ZMS*Managers with ExternalMethod support may affected and must be addressed.

References:

Screenshot 2026-05-06 at 14 06 59 Screenshot 2026-05-06 at 13 39 20

@cmeier76 cmeier76 requested a review from drfho May 6, 2026 12:33
@cmeier76 cmeier76 self-assigned this May 6, 2026
@drfho
Copy link
Copy Markdown
Contributor

drfho commented May 6, 2026

good idea to monotonize it.
I removed the extra-info in case of missing artefact and prepended that info to the error-info block within the textarea. Moreover there the warning-icon appears as an eye-catcher:

image

Copy link
Copy Markdown
Contributor

@drfho drfho left a comment

Choose a reason for hiding this comment

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

LTGM, ready for merge

added helper function for upfront syntax check to addExternalMethod

Co-authored-by: Copilot <copilot@github.com>
@drfho
Copy link
Copy Markdown
Contributor

drfho commented May 6, 2026

Code-Errors in Meta-Cmds

Following this approach I tried to fit error messages of meta-cmds as well: it is tricky, because ExtMethod (in contrast to PyScript or ZPT) dont provide syntax validation by Zope. Until now a wrong py-syntax (e.g. import of not-installed module) just broke saving and thus the Zope object (the pointer to the external method) was not deleted - by chance. If the code was once broken, you could not repair it via ZMI.
I added a helper function for checking the py-syntax (incl. imports): zopeutil.addExternalMethod.upfront_syntax_check(data)
to avoid the ExtMethod-reloading/recompiling in case of code-errors.
Now its possiible to repair a defect cmd in ZMI instead of e.g. unloading via repo-manager.

def upfront_syntax_check(data):
import ast
import importlib.util
try:
tree = ast.parse(data, filename=filepath)
except SyntaxError as e:
standard.writeError(container, "[SyntaxError in External Method '%s']: %s"%(id, str(e)))
return False
missing = []
for node in ast.walk(tree):
if isinstance(node, ast.Import):
names = [alias.name for alias in node.names]
elif isinstance(node, ast.ImportFrom):
names = [node.module] if node.module else []
else:
continue
for name in names:
top = name.split('.')[0]
if importlib.util.find_spec(top) is None:
missing.append(name)
if missing:
standard.writeError(container, "[Missing imports in External Method '%s']: %s"%(id, ', '.join(missing)))
return False
return True

image

Copy link
Copy Markdown
Contributor

@zmsdev zmsdev left a comment

Choose a reason for hiding this comment

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

LGTM

@cmeier76
Copy link
Copy Markdown
Member Author

cmeier76 commented May 7, 2026

@drfho Now I'm missing the hint from the thrown exception that I introduced earlier to locate the problem in the code - but maybe the general error message will be sufficient

@cmeier76
Copy link
Copy Markdown
Member Author

cmeier76 commented May 7, 2026

BTW. For zms.unibe.agenda.OutlookConnector I introduced in zms.unibe-2026.2.0 a handling of missing MS Graph API support and disabling if not available

@drfho drfho marked this pull request as ready for review May 7, 2026 09:59
@drfho drfho merged commit 8a81739 into main May 7, 2026
12 checks passed
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.

3 participants