- Notifications
You must be signed in to change notification settings - Fork749
Better error messages for method argument mismatch and others#1361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
716c98d
Better error messages for method argument mismatch, Python to managed…
tminka94b0c35
PythonException.Normalize throws if an error is set
tminka914f0e6
ExceptionClassObject.tp_str calls Exception.ToString() instead of Exc…
tminka1caded0
Revert change to GetAggregateException
tminkab8a7b9e
Disabled test_method_parameters_change
tminkaFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletionsCHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletionssrc/clrmodule/ClrModule.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionssrc/domain_tests/test_domain_reload.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletionssrc/embed_tests/TestPythonException.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
15 changes: 12 additions & 3 deletionssrc/runtime/classbase.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
73 changes: 58 additions & 15 deletionssrc/runtime/converter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
22 changes: 7 additions & 15 deletionssrc/runtime/eventbinding.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
11 changes: 8 additions & 3 deletionssrc/runtime/eventobject.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
46 changes: 39 additions & 7 deletionssrc/runtime/exceptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
namespace Python.Runtime | ||
{ | ||
@@ -71,14 +72,16 @@ internal static Exception ToException(IntPtr ob) | ||
return Exceptions.RaiseTypeError("invalid object"); | ||
} | ||
string message = e.ToString(); | ||
string fullTypeName = e.GetType().FullName; | ||
string prefix = fullTypeName + ": "; | ||
if (message.StartsWith(prefix)) | ||
{ | ||
message =message.Substring(prefix.Length); | ||
} | ||
elseif (message.StartsWith(fullTypeName)) | ||
{ | ||
message = message.Substring(fullTypeName.Length); | ||
} | ||
return Runtime.PyUnicode_FromString(message); | ||
} | ||
@@ -181,6 +184,7 @@ internal static void SetArgsAndCause(IntPtr ob) | ||
if (e.InnerException != null) | ||
{ | ||
// Note: For an AggregateException, InnerException is only the first of the InnerExceptions. | ||
lostmsu marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
IntPtr cause = CLRObject.GetInstHandle(e.InnerException); | ||
Marshal.WriteIntPtr(ob, ExceptionOffset.cause, cause); | ||
} | ||
@@ -290,6 +294,20 @@ public static void SetError(Exception e) | ||
Runtime.XDecref(op); | ||
} | ||
/// <summary> | ||
/// When called after SetError, sets the cause of the error. | ||
/// </summary> | ||
/// <param name="cause">The cause of the current error</param> | ||
public static void SetCause(PythonException cause) | ||
{ | ||
var currentException = new PythonException(); | ||
currentException.Normalize(); | ||
cause.Normalize(); | ||
Runtime.XIncref(cause.PyValue); | ||
Runtime.PyException_SetCause(currentException.PyValue, cause.PyValue); | ||
currentException.Restore(); | ||
} | ||
/// <summary> | ||
/// ErrorOccurred Method | ||
/// </summary> | ||
@@ -368,17 +386,31 @@ public static void deprecation(string message) | ||
// Internal helper methods for common error handling scenarios. | ||
//==================================================================== | ||
/// <summary> | ||
/// Raises a TypeError exception and attaches any existing exception as its cause. | ||
/// </summary> | ||
/// <param name="message">The exception message</param> | ||
/// <returns><c>IntPtr.Zero</c></returns> | ||
internal static IntPtr RaiseTypeError(string message) | ||
{ | ||
PythonException previousException = null; | ||
if (ErrorOccurred()) | ||
{ | ||
previousException = new PythonException(); | ||
} | ||
Exceptions.SetError(Exceptions.TypeError, message); | ||
if (previousException != null) | ||
{ | ||
SetCause(previousException); | ||
} | ||
return IntPtr.Zero; | ||
} | ||
// 2010-11-16: Arranged in python (2.6 & 2.7) source header file order | ||
/* Predefined exceptions are | ||
public static variables on the Exceptions class filled in from | ||
the python class using reflection in Initialize() looked up by | ||
name, notposition. */ | ||
public static IntPtr BaseException; | ||
public static IntPtr Exception; | ||
public static IntPtr StopIteration; | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.