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

cppyy (pyroot) incorrectly claiming TypeError from overloaded methods that throw exceptions #16405

Open
1 task
will-cern opened this issue Sep 11, 2024 · 3 comments

Comments

@will-cern
Copy link
Contributor

Check duplicate issues.

  • Checked for duplicates

Description

I have a class with some overloaded methods that are designed to throw exceptions if the user messes up. In non-overloaded methods this exception is passed back to the user, exactly as expected. But when the method is overloaded, cppyy seems to assume that the failure was a TypeError issue rather than returning the underlying exception. Below is a reproducer.

Reproducer

import ROOT

ROOT.gInterpreter.ProcessLine("""
class MyClass {
public:
    class MyObj {
    public:
        MyObj(const char*) { }
    };
    void MyMethod(const MyObj& x = "") {
      throw std::runtime_error("My exception");
    }
    void MyMethod(const MyObj& x, bool another) {
      throw std::runtime_error("My second exception");
    }

};
""")
MyClass().MyMethod("hi")

Produces:

TypeError: none of the 2 overloaded methods succeeded. Full details:
  void MyClass::MyMethod(const MyClass::MyObj& x, bool another) =>
    TypeError: takes at least 2 arguments (1 given)
  void MyClass::MyMethod(const MyClass::MyObj& x = "") =>
    TypeError: could not convert argument 1

The issue is the second exception, since there isn't a conversion error here. Pyroot should report the exception (runtime_error("My Exception")) here instead.

ROOT version

6.32

Installation method

source

Operating system

all

Additional context

No response

@guitargeek
Copy link
Contributor

guitargeek commented Sep 11, 2024

Hi @will-cern! Just to double check with you before closing this issue as duplicate: this is the same as #9909, right? Coincidentally, reported by Carsten 🙂

In case it is really a duplicate, please close this issue here and make a comment in Carstens issue, so that it's documented that more than one person cares about it and we can bump the priority and have a discussion at a central place.

@will-cern
Copy link
Contributor Author

Actually I think it's different to that issue. In the other issue he wanted pyROOT to throw one of the exceptions, but it at least is telling the user what the exception types were from each of the c++ methods it tried. In my case, I'm unhappy that pyROOT seems to be hiding the exceptions that c++ threw behind a TypeError, rather than saying the correct exception type (which was a runtime error, and ideally to print the message associated to that).

@will-cern
Copy link
Contributor Author

Maybe to be clearer, I would expect the output to be:

TypeError: none of the 2 overloaded methods succeeded. Full details:
  void MyClass::MyMethod(const MyClass::MyObj& x, bool another) =>
    TypeError: takes at least 2 arguments (1 given)
  void MyClass::MyMethod(const MyClass::MyObj& x = "") =>
    RuntimeError: My exception

I.e. the second method didn't fail because of a conversion type error, it failed because the method threw a runtime exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants