From 456a4f363118837959d4beb3800a7666b62b585e Mon Sep 17 00:00:00 2001
From: Daniel Sali <daniel.sali@alphacruncher.com>
Date: Wed, 8 Jan 2025 16:05:52 +0100
Subject: [PATCH] Raise DynareError if Context couldn't be produced from the
 model file

---
 src/dynare/dynare.py | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/src/dynare/dynare.py b/src/dynare/dynare.py
index d0be355..bb17fab 100644
--- a/src/dynare/dynare.py
+++ b/src/dynare/dynare.py
@@ -182,18 +182,14 @@ def dynare(model: str | Path) -> Context:
         end
         """
         )
-        jl.seval(f'@dynare "{resolved_path}"')
-
-        jls_path = model.parent / model.stem / "output" / f"{model.stem}.jls"
-
-        if not jls_path.exists():
-            raise DynareError(
-                f"Model evaluation failed. No JLS file found at {jls_path}"
-            )
-
         context = jl.seval(
-            f"""ctx = Serialization.deserialize("{jls_path.resolve()}");
-                convert_to_pycontext(ctx)"""
+            f"""ctx = @dynare "{resolved_path}";
+            if !(ctx isa Dynare.Context)
+                throw(error("Failed to produce a Dynare context."))
+            else
+                convert_to_pycontext(ctx)
+            end
+            """
         )
         return Context.from_julia(context)
     except JuliaError as e:
-- 
GitLab