Skip to content

Commit

Permalink
Get error cause once (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz authored Oct 20, 2024
1 parent 63575cf commit 68bf2d4
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/CSnakes.Runtime/PythonRuntimeException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ public PythonRuntimeException(PyObject? exception, PyObject? traceback): base(ex
Data["globals"] = traceback.GetAttr("tb_frame").GetAttr("f_globals").As<IReadOnlyDictionary<string, PyObject>>();
}

private static PythonRuntimeException? GetPythonInnerException(PyObject? exception)
{
if (exception is null)
{
return null;
}
if (exception.HasAttr("__cause__") && !exception.GetAttr("__cause__").IsNone())
{
return new PythonRuntimeException(exception.GetAttr("__cause__"), null);
}
return null;
}
private static PythonRuntimeException? GetPythonInnerException(PyObject? exception) =>
exception is { } someException
&& someException.HasAttr("__cause__")
&& someException.GetAttr("__cause__") is var cause
&& !cause.IsNone()
? new PythonRuntimeException(cause, null)
: null;

public string[] PythonStackTrace
{
Expand Down

0 comments on commit 68bf2d4

Please sign in to comment.