Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Repair OpaqueError #300

Merged
merged 1 commit into from
Oct 17, 2023
Merged

feat: Repair OpaqueError #300

merged 1 commit into from
Oct 17, 2023

Conversation

ajewellamz
Copy link
Contributor

Issue #, if available:

Description of changes:

OpaqueError has two constructors :
OpaqueError(Exception ex) : base("OpaqueError:", ex) { this.obj = ex; }
OpaqueError(object obj) : base("Opaque obj is not an Exception.") { this.obj = obj;}

Unfortunately, overloading is resolved at compile time, so if you have an Exception currently cast to an Object, you get the second one, and therefore lose all the information in the original Exception.
Even more unfortunately, the thing that turns an extern's Error_Opaque into an OpaqueError does exactly that : casts the original Exception to an Object before use.

The solution is to change the second constructor to behave differently if the Object is really an Exception

OpaqueError(object obj)
: base(obj is Exception ? "OpaqueError:" : "Opaque obj is not an Exception.", obj as Exception)
{ this.obj = obj;}

"obj as Exception" is either an Exception, in which case we get back the context, or null, which is exactly the old behavior.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ajewellamz ajewellamz requested a review from a team as a code owner October 17, 2023 13:36
Copy link
Contributor

@texastony texastony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR description!
Really helps clarify what is going on

@ajewellamz ajewellamz merged commit 72f7e32 into main-1.x Oct 17, 2023
54 checks passed
@ajewellamz ajewellamz deleted the repair-opaque-error branch October 17, 2023 18:15
ShubhamChaturvedi7 pushed a commit to ShubhamChaturvedi7/smithy-dafny that referenced this pull request Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants