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.
A couple of patterns have emerged to report TransformationErrors
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.So we end up with something like:
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.