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

Allow throwing of edm::Exceptions from python #40315

Merged
merged 1 commit into from Dec 17, 2022

Conversation

Dr15Jones
Copy link
Contributor

PR description:

Only a selected set of edm::errors codes are allowed.

PR validation:

Code compiles and a simple script shows it works.

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-40315/33395

@cmsbuild
Copy link
Contributor

A new Pull Request was created by @Dr15Jones (Chris Jones) for master.

It involves the following packages:

  • FWCore/Framework (core)
  • FWCore/ParameterSet (core)
  • FWCore/PythonParameterSet (core)

@cmsbuild, @smuzaffar, @Dr15Jones, @makortel can you please review it and eventually sign? Thanks.
@makortel, @missirol, @wddgit this is something you requested to watch as well.
@perrotta, @dpiparo, @rappoccio you are the release manager for this.

cms-bot commands are listed here

@Dr15Jones
Copy link
Contributor Author

please test

Copy link
Contributor

@makortel makortel left a comment

Choose a reason for hiding this comment

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

How about adding a unit test?

@@ -39,6 +40,8 @@ PYBIND11_MODULE(libFWCorePythonParameterSet, m) {
std::rethrow_exception(p);
} catch (const cms::Exception &e) {
PyErr_SetString(PyExc_RuntimeError, e.what());
} catch (const pybind11::error_already_set &e) {
std::cout << "pybind " << e.what() << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this printout still useful?

auto errorNameEnd = error.find('}');
if (errorNameStart != std::string::npos and errorNameEnd != std::string::npos) {
auto errorName = error.substr(errorNameStart + 1, errorNameEnd - errorNameStart - 1);
std::cout << "EDMException '" << errorName << "'" << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this printout be removed?

auto errorName = error.substr(errorNameStart + 1, errorNameEnd - errorNameStart - 1);
std::cout << "EDMException '" << errorName << "'" << std::endl;
if ("Configuration" == errorName) {
std::cout << "throwing edm::Exception" << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this printout be removed?

if (errorNameStart != std::string::npos and errorNameEnd != std::string::npos) {
auto errorName = error.substr(errorNameStart + 1, errorNameEnd - errorNameStart - 1);
std::cout << "EDMException '" << errorName << "'" << std::endl;
if ("Configuration" == errorName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be feasible to generalize the name-to-error code translation by exploiting the information in

static const std::map<ErrorCodes, std::string> codeMap = {FILLENTRY(CommandLineProcessing),
FILLENTRY(ConfigFileNotFound),

?

On the other hand, the number of error codes to throw from the python code is likely small (I can think of one to add, but not really more)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd prefer to only allow a very select few edm.errors to be used.

Configuration = "{Configuration}"

class EDMException(Exception):
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not crystal clear to me how these would be used. Based on the implementation I'd guess

raise EDMException(edm.error.Configuration + "Real exception message")

How about something along the following interface?

raise EDMException(edm.error.Configuration, "Real exception message")

@@ -240,6 +240,8 @@ int main(int argc, char* argv[]) {
try {
std::unique_ptr<edm::ParameterSet> parameterSet = edm::readConfig(fileName, argc, argv);
processDesc.reset(new edm::ProcessDesc(std::move(parameterSet)));
} catch (edm::Exception const&) {
throw;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if adding the calling context to the exception would be helpful to interpret the exception message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The call actually does have a lot of context. E.g.

----- Begin Fatal Exception 14-Dec-2022 14:21:44 CST-----------------------
An exception of category 'Configuration' occurred while
   [0] Processing the python configuration file named test_pyhon_error.py
Exception Message:
test message

At:
  test_pyhon_error.py(11): <module>
----- End Fatal Exception -------------------------------------------------

for my trivial test case where the configuration file only has the raise call.

Only a selected set of edm::errors codes are allowed.
@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-40315/33396

@cmsbuild
Copy link
Contributor

Pull request #40315 was updated. @cmsbuild, @smuzaffar, @Dr15Jones, @makortel can you please check and sign again.

@Dr15Jones
Copy link
Contributor Author

please test

@cmsbuild
Copy link
Contributor

+1

Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-baccdf/29659/summary.html
COMMIT: 6e6d795
CMSSW: CMSSW_13_0_X_2022-12-16-1100/el8_amd64_gcc11
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week1/cms-sw/cmssw/40315/29659/install.sh to create a dev area with all the needed externals and cmssw changes.

Comparison Summary

Summary:

  • No significant changes to the logs found
  • Reco comparison results: 6 differences found in the comparisons
  • DQMHistoTests: Total files compared: 49
  • DQMHistoTests: Total histograms compared: 3557521
  • DQMHistoTests: Total failures: 3
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 3557496
  • DQMHistoTests: Total skipped: 22
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 48 files compared)
  • Checked 211 log files, 162 edm output root files, 49 DQM output files
  • TriggerResults: no differences found

@makortel
Copy link
Contributor

+1

@cmsbuild
Copy link
Contributor

This pull request is fully signed and it will be integrated in one of the next master IBs (tests are also fine). This pull request will now be reviewed by the release team before it's merged. @perrotta, @dpiparo, @rappoccio (and backports should be raised in the release meeting by the corresponding L2)

@perrotta
Copy link
Contributor

+1

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

Successfully merging this pull request may close these issues.

None yet

4 participants