|
2 | 2 | using System.Collections; |
3 | 3 | using System.Collections.Generic; |
4 | 4 | using System.Linq; |
| 5 | +using System.Reflection; |
5 | 6 | using Autodesk.DesignScript.Runtime; |
6 | 7 | using DSPythonNet3.Encoders; |
7 | 8 | using Dynamo.Events; |
@@ -290,7 +291,7 @@ public override object Evaluate( |
290 | 291 | if (!string.IsNullOrEmpty(traceBack)) |
291 | 292 | { |
292 | 293 | // Throw a new error including trace back info added to the message |
293 | | - throw new InvalidOperationException($"{e.Message} {traceBack}", e); |
| 294 | + throw new InvalidOperationException($"{e.Message}\n{traceBack}", e); |
294 | 295 | } |
295 | 296 | else |
296 | 297 | { |
@@ -439,19 +440,19 @@ private static void InitializeEncoders() |
439 | 440 | /// <returns>Trace back message</returns> |
440 | 441 | private static string GetTraceBack(Exception e) |
441 | 442 | { |
442 | | - var pythonExc = e as PythonException; |
443 | | - if (!(e is PythonException)) |
| 443 | + if (e is not PythonException pythonExc) |
444 | 444 | { |
445 | 445 | return null; |
446 | 446 | } |
447 | 447 |
|
448 | 448 | // Return the value of the trace back field (private) |
449 | | - var field = pythonExc.Traceback; |
| 449 | + var field = typeof(PythonException).GetMethod("TracebackToString", BindingFlags.NonPublic | BindingFlags.Static); |
450 | 450 | if (field == null) |
451 | 451 | { |
452 | 452 | throw new NotSupportedException(Properties.Resources.InternalErrorTraceBackInfo); |
453 | 453 | } |
454 | | - return field.ToString(); |
| 454 | + |
| 455 | + return (string)field.Invoke(pythonExc, [pythonExc.Traceback]); |
455 | 456 | } |
456 | 457 |
|
457 | 458 | #region Marshalling |
|
0 commit comments