From 5a596ab8e04655b4b95f14bf8d63d6d6448edd58 Mon Sep 17 00:00:00 2001 From: jplfaria Date: Tue, 30 Jun 2026 06:47:53 +0000 Subject: [PATCH 1/2] fix: catch TypeError from malformed RAST server error response (ops#19) --- src/modelseed_api/services/genome_annotator.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modelseed_api/services/genome_annotator.py b/src/modelseed_api/services/genome_annotator.py index ce07acd..594b52c 100644 --- a/src/modelseed_api/services/genome_annotator.py +++ b/src/modelseed_api/services/genome_annotator.py @@ -183,6 +183,8 @@ def annotate_fasta( [genome_dict, {"stages": stages}], ) break + except TypeError as exc: + raise RuntimeError("RAST malformed error response (expected dict, got str). Original: " + str(exc)) from exc except Exception as exc: msg = str(exc) is_transient = any(code in msg for code in _TRANSIENT_5XX) From 7afe4ddd4d85fee852adf68c3cad24db7af8efb4 Mon Sep 17 00:00:00 2001 From: jplfaria Date: Tue, 30 Jun 2026 06:50:01 +0000 Subject: [PATCH 2/2] test: add regression test for TypeError from malformed RAST response (ops#19) --- tests/unit/test_genome_annotator.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/unit/test_genome_annotator.py b/tests/unit/test_genome_annotator.py index 558c518..7a1e181 100644 --- a/tests/unit/test_genome_annotator.py +++ b/tests/unit/test_genome_annotator.py @@ -178,3 +178,20 @@ def call(self, method, params): with pytest.raises(ValueError, match="no.*functional roles"): annotate_fasta(">p1\nMKKLVAVLIVSLAVALSALAVA") + + + +class TestAnnotateFastaTypeErrorHandling: + def test_rpc_typeerror_wraps_to_runtimeerror(self, monkeypatch): + class BadErrorClient: + def __init__(self, url, timeout=600): + pass + def call(self, method, params): + raise TypeError( + "argument after ** must be a mapping, not str" + ) + monkeypatch.setattr( + "modelseed_api.services.genome_annotator.RPCClient", BadErrorClient, + ) + with pytest.raises(RuntimeError, match="malformed error response"): + annotate_fasta(">p1\nMKKLVAVLIVSLAVALSALAVA") \ No newline at end of file