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

C# unexpectedly wraps errors in System.Reflection.TargetInvocationException #6817

Closed
jdonaldson opened this issue Jan 12, 2018 · 1 comment · Fixed by #11551
Closed

C# unexpectedly wraps errors in System.Reflection.TargetInvocationException #6817

jdonaldson opened this issue Jan 12, 2018 · 1 comment · Fixed by #11551
Labels
platform-cs Everything related to c#
Milestone

Comments

@jdonaldson
Copy link
Member

This is really tough to minimize, but occasionally the C# target will throw an error that is a wrapped version of the one I expect. Specifically, it looks like this wrapper is used.

I've boiled the behavior down to a test case, which I'll link shortly.

@jdonaldson
Copy link
Member Author

jdonaldson commented Jan 12, 2018

Well, this turns out to be difficult to reproduce. I can't get it to fail using the Haxe test runner, only the old unit test version. Here's a standalone repro:

-main RunTests.hx
-cp src
-cp tests
-cp ../hx3compat/std/ # link to the old hx3compat test runner.
-cmd mono bin/test/bin/RunTests.exe
-cs bin/test
package ;
import haxe.unit.*;


class RunTests {
  static function main() {
    var r = new TestRunner();
    r.add(new WrappedError());
    trace(r.run() ? 0 : 500);
  }

}

class WrappedError extends haxe.unit.TestCase {
    public function testWrappedError(){
        var api = new TestApi();
        try{
            Runner.run(api);
            trace("the above should throw an error");
            assertTrue(false);
        } catch (e : Error) {
            trace(e + " is the value for e");
            var res = switch(e){
                case Expected : true;
                default : false;
            }
            assertTrue(res);
            trace("The catch block should have caught an expected error type, instead we got:\n" + e);
            assertTrue(false);
        }
    }

}



class TestApi extends Api<Dynamic> {
    // Suspicious : If I remove this dummy function, the test passes
    public function dummy()  { }

    // Suspicious : If I remove this override, the test passes
    override public function exec( params: Dynamic)  : String {
        throw Expected;
        return 'hi';
    }

}

// Suspicious : If I drop this irrelevant Dynamic parameter, the test passes.
class Api<Dynamic> {

    public function new(){ }

    public function exec( params: Dynamic)  : String {
        throw Expected;
        return 'hi';
    }
}

class Runner{
    public static function run( api : Api<Dynamic>) {
        api.exec(null);
    }

}

enum Error {
	Expected;
}

@jdonaldson jdonaldson added the platform-cs Everything related to c# label Jan 12, 2018
@Simn Simn added this to the Bugs milestone Apr 17, 2018
@Simn Simn modified the milestones: Bugs, Later Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-cs Everything related to c#
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants