def get_process_errors_js(expression):
    """
    Return JS code which evaluates an ``expression`` and
    returns ``{error: false, result: ...}`` if there is no exception
    or ``{error: true, errorType: ..., errorMessage: ..., errorRepr: ...}``
    if expression raised an error when evaluating.
    """
    return (
        u"""
    (function () {
      try {
        return {
          error: false,
          result: %(expression)s,
        }
      }
      catch (e) {
        return {
          error: true,
          errorType: e.name,
          errorMessage: e.message,
          errorRepr: e.toString(),
        };
      }
    })()
    """
         % dict(expression=expression))
