Skip to content

Commit

Permalink
implement error message in job
Browse files Browse the repository at this point in the history
  • Loading branch information
korgan00 committed Oct 25, 2024
1 parent 4f29082 commit 24a1727
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions client/qiskit_serverless/core/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
GATEWAY_PROVIDER_VERSION_DEFAULT,
)

from qiskit_serverless.exception import QiskitServerlessException
from qiskit_serverless.serializers.program_serializers import (
QiskitObjectsEncoder,
QiskitObjectsDecoder,
Expand Down Expand Up @@ -125,6 +126,10 @@ def filtered_logs(self, **kwargs) -> str:
"""
return self._client.filtered_logs(job_id=self.job_id, **kwargs)

def error_message(self):
"""Returns the execution error message."""
return self._client.result(self.job_id) if self.status() == "ERROR" else ""

def result(self, wait=True, cadence=5, verbose=False, maxwait=0):
"""Return results of the job.
Args:
Expand All @@ -145,6 +150,11 @@ def result(self, wait=True, cadence=5, verbose=False, maxwait=0):
if verbose:
logging.info(count)

if self.status() == "ERROR":
raise QiskitServerlessException(
"Job finished with an error. Use error_message() to get additional information."
)

# Retrieve the results. If they're string format, try to decode to a dictionary.
results = self._client.result(self.job_id)
if isinstance(results, str):
Expand Down

0 comments on commit 24a1727

Please sign in to comment.