Beispiel #1
0
def main():
    args, unknown_args = parse_args()

    out_dir: Path = args.out_dir
    preexec(out_dir)
    retcode: int

    with (out_dir / "logs.txt").open("w") as stream_logs, (
            out_dir / "results.json").open("w") as results_stream:
        try:
            # check cli compatible with server - should never really fail
            if args.server_version:
                is_version_compatible(args.server_version, __version__)

            # read the config files
            # NOTE - we could supply config also by env-var or already write k8s volume in the future
            run_config = decode(args.config, compressed=True)
            setup_api(args.dp_token, args.dp_host, args.debug, stream_logs)
            res = run_api(run_config)
        except ModelRunError as e:
            ErrorResult(error=e.error,
                        error_detail=e.details).to_json(results_stream)
            retcode = 103  # NOTE - all user errors return 103
        except Exception:
            log.exception("Unhandled Exception in Model Runner")
            # we could send traceback as details, but not useful to end user
            ErrorResult(error="Unhandled Exception",
                        debug=traceback.format_exc()).to_json(results_stream)
            retcode = 104
        else:
            res.to_json(results_stream)
            retcode = 0

    sys.exit(retcode)
Beispiel #2
0
def api_error_handler(err_msg: str):
    try:
        yield
    except HTTPError as e:
        if EXTRA_OUT:
            log.exception(e)
        else:
            log.error(e)
        failure_msg(err_msg, do_exit=True)
Beispiel #3
0
 def __call__(self, *args, **kwargs):
     try:
         return self.main(*args, **kwargs)
     except Exception as e:
         analytics.capture("CLI Error", dict(msg=str(e), type=str(type(e))))
         if EXTRA_OUT:
             log.exception(e)
         if isinstance(e, utils.DPError):
             failure_msg(str(e))
         else:
             failure_msg(utils.add_help_text(str(e)), do_exit=True)
Beispiel #4
0
 def __call__(self, *args, **kwargs):
     try:
         return self.main(*args, **kwargs)
     except api.IncompatibleVersionException as exc:
         if EXTRA_OUT:
             log.exception(exc)
         failure_msg(str(exc))
     except HTTPError as e:
         if EXTRA_OUT:
             log.exception(e)
         failure_msg(str(e), do_exit=True)
     except Exception as e:
         if EXTRA_OUT:
             log.exception(e)
         failure_msg(str(e), do_exit=True)
Beispiel #5
0
 def __call__(self, *args, **kwargs):
     try:
         return self.main(*args, **kwargs)
     except utils.IncompatibleVersionError as e:
         if EXTRA_OUT:
             log.exception(e)
         failure_msg(str(e))
     except HTTPError as e:
         if EXTRA_OUT:
             log.exception(e)
         failure_msg(utils.add_help_text(str(e)), do_exit=True)
     except Exception as e:
         if EXTRA_OUT:
             log.exception(e)
         failure_msg(utils.add_help_text(str(e)), do_exit=True)