failure.py 654 B

123456789101112131415161718192021222324
  1. from macropy.core.macros import *
  2. from macropy.core.hquotes import macros, hq
  3. import traceback
  4. class MacroExpansionError(Exception):
  5. def __init__(self, message):
  6. Exception.__init__(self, message)
  7. def raise_error(ex):
  8. raise ex
  9. @register(filters)
  10. def clear_errors(tree, **kw):
  11. if isinstance(tree, Exception):
  12. tb = traceback.format_exc()
  13. msg = tree.message
  14. if type(tree) is not AssertionError or tree.args == ():
  15. msg = "".join(tree.args) + "\nCaused by Macro-Expansion Error:\n" + tb
  16. return hq[raise_error(MacroExpansionError(msg))]
  17. else:
  18. return tree