Skip to content

Commit

Permalink
forward incoming error when decoding fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Villar authored and victor-villar committed Aug 12, 2024
1 parent 1413b92 commit 119cf5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
6 changes: 4 additions & 2 deletions qiskit_transpiler_service/wrappers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def _raise_transpiler_error_and_log(msg: str):


def _get_error_msg_from_response(exc: requests.exceptions.HTTPError):
if exc.response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY.value:
try:
resp = exc.response.json()
detail = resp.get("detail")
# Default message
Expand All @@ -194,6 +194,8 @@ def _get_error_msg_from_response(exc: requests.exceptions.HTTPError):

if detail_input and detail_msg:
msg = f"Wrong input '{detail_input}'. {detail_msg}"
else:
except:
# If something fails decoding the error
# just show the incoming error
msg = f"Internal error: {str(exc)}"
return msg
27 changes: 5 additions & 22 deletions tests/test_transpiler_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,26 +175,6 @@ def test_transpile_non_valid_backend():
)


def test_wrong_url():
random_circ = random_circuit(5, depth=2, seed=42)
transpiler_service = TranspilerService(
backend_name="ibm_kyoto",
ai="false",
optimization_level=3,
)

transpiler_service.transpiler_service.url = "https://cloud-transpiler-experimental.quantum.ibm.com/INVALID"

try:
transpiler_service.run(random_circ)
pytest.fail("Error expected")
except Exception as e:
assert (
"Internal error: 404 Client Error: Not Found for url:" in
str(e)
)


def test_transpile_exceed_circuit_size():
circuit = EfficientSU2(120, entanglement="full", reps=5).decompose()
transpiler_service = TranspilerService(
Expand Down Expand Up @@ -259,8 +239,11 @@ def test_transpile_wrong_url():
transpiler_service.run(circuit)
pytest.fail("Error expected")
except Exception as e:
assert "Expecting value: line 1 column 1 (char 0)" in str(e)
assert type(e).__name__ == "JSONDecodeError"
assert (
"Internal error: 404 Client Error: Not Found for url: https://www.ibm.com/transpile"
in str(e)
)
assert type(e).__name__ == "TranspilerError"


@pytest.mark.disable_monkeypatch
Expand Down

0 comments on commit 119cf5d

Please sign in to comment.