PSyclone icon indicating copy to clipboard operation
PSyclone copied to clipboard

Encapsulate TransformationError reporting functionality

Open sergisiso opened this issue 7 months ago • 0 comments

A couple of patterns have emerged to report TransformationErrors

  • TransformationErrors often need the context of when they happen in the error message, the easy way to do it is with node.debug_string(), but since this invokes the backend it is a lot of work to create a string that will sometimes be just ignored. So we recommend using LazyString to delay the call to the visitor.
  • TransformationErrors are often purposely ignored, but sometimes want to still keep track of the reason. In this cases we started adding it as a comment when the verbose option is provided.

So we end up with something like:

message = (f"My error message without view or debug_string")
if verbose:
    node.append_preceding_comment(message)
raise TransformationError(LazyString(
    lambda: f"{message}, but found:\n{node.debug_string()}"))

We could encapsulate this is a method so that it is a single-liner to call, but also because we could have the message syntax be more predictable, e.g. we may want to prefix all psyclone added comments with a specific identifier and in the future we may want to make the reporting configurable: e.g. comment/logfile/stderr, so it would be good to do in in a single place and not all over the code.

sergisiso avatar Jul 23 '24 13:07 sergisiso