Exemple #1
0
    def test_record_exception(self):
        with patch.dict(os.environ,
                        {"TORCHELASTIC_ERROR_FILE": self.test_error_file}):
            eh = ErrorHandler()
            eh.initialize()

            try:
                raise_exception_fn()
            except Exception as e:
                eh.record_exception(e)

            with open(self.test_error_file, "r") as fp:
                err = json.load(fp)
                # error file content example:
                # {
                #   "message": {
                #     "message": "RuntimeError: foobar",
                #     "extraInfo": {
                #       "py_callstack": "Traceback (most recent call last):\n  <... OMITTED ...>",
                #       "timestamp": "1605774851"
                #     }
                #   }
            self.assertIsNotNone(err["message"]["message"])
            self.assertIsNotNone(err["message"]["extraInfo"]["py_callstack"])
            self.assertIsNotNone(err["message"]["extraInfo"]["timestamp"])
Exemple #2
0
 def test_record_exception_no_error_file(self):
     # make sure record does not fail when no error file is specified in env vars
     with patch.dict(os.environ, {}):
         eh = ErrorHandler()
         eh.initialize()
         try:
             raise_exception_fn()
         except Exception as e:
             eh.record_exception(e)