Skip to content

Commit

Permalink
#13334: Capture exception class when recording job error
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Dec 1, 2023
1 parent 0340a5e commit 0c9919a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion netbox/core/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def sync_datasource(job, *args, **kwargs):
job.terminate()

except Exception as e:
job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=str(e))
job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=repr(e))
DataSource.objects.filter(pk=datasource.pk).update(status=DataSourceStatusChoices.FAILED)
if type(e) in (SyncError, JobTimeoutException):
logging.error(e)
Expand Down
2 changes: 1 addition & 1 deletion netbox/extras/management/commands/runscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _run_script():
logger.error(f"Exception raised during script execution: {e}")
clear_events.send(request)
job.data = ScriptOutputSerializer(script).data
job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=str(e))
job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=repr(e))

logger.info(f"Script completed in {job.duration}")

Expand Down
4 changes: 2 additions & 2 deletions netbox/extras/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def run_report(job, *args, **kwargs):
try:
report.run(job)
except Exception as e:
job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=str(e))
job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=repr(e))
logging.error(f"Error during execution of report {job.name}")
finally:
# Schedule the next job if an interval has been set
Expand Down Expand Up @@ -230,7 +230,7 @@ def run(self, job):
stacktrace = traceback.format_exc()
self.log_failure(None, f"An exception occurred: {type(e).__name__}: {e} <pre>{stacktrace}</pre>")
logger.error(f"Exception raised during report execution: {e}")
job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=str(e))
job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=repr(e))

# Perform any post-run tasks
self.post_run()
Expand Down
2 changes: 1 addition & 1 deletion netbox/extras/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def _run_script():
logger.error(f"Exception raised during script execution: {e}")
script.log_info("Database changes have been reverted due to error.")
job.data = ScriptOutputSerializer(script).data
job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=str(e))
job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=repr(e))
if request:
clear_events.send(request)

Expand Down

0 comments on commit 0c9919a

Please sign in to comment.