From 78990e9db3227c38bdb25c5fd660872a2e311a11 Mon Sep 17 00:00:00 2001 From: Jacob Szwejbka Date: Mon, 30 Sep 2024 11:44:44 -0700 Subject: [PATCH] throw instead of segfault with invalid args in pybindings (#5726) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/5726 Fixed some Error() call sites and added better checking on the method name Reviewed By: larryliu0820, dbort Differential Revision: D63547425 fbshipit-source-id: 69e32f90cbc2607b75df5186b0289fe385ce95e3 (cherry picked from commit 972071572162ecd7edcaa286b31a549b989b6bf8) --- extension/pybindings/pybindings.cpp | 2 +- extension/pybindings/test/make_test.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/extension/pybindings/pybindings.cpp b/extension/pybindings/pybindings.cpp index 19d4d095963..de9119c1056 100644 --- a/extension/pybindings/pybindings.cpp +++ b/extension/pybindings/pybindings.cpp @@ -140,7 +140,7 @@ void setup_output_storage( const std::vector>& output_storages) { if (output_storages.size() != method.outputs_size()) { THROW_IF_ERROR( - Error(), + Error::InvalidArgument, "number of output storages %zu does not match number of outputs %zu", output_storages.size(), method.outputs_size()); diff --git a/extension/pybindings/test/make_test.py b/extension/pybindings/test/make_test.py index e8d23fd44e6..5335df1a0b1 100644 --- a/extension/pybindings/test/make_test.py +++ b/extension/pybindings/test/make_test.py @@ -305,6 +305,7 @@ def test_constant_output_not_memory_planned(tester): ######### RUN TEST CASES ######### def test_method_meta(tester) -> None: + # pyre-fixme[16]: Callable `make_test` has no attribute `wrapper`. exported_program, inputs = create_program(ModuleAdd()) # Use pybindings to load the program and query its metadata. @@ -351,6 +352,7 @@ def test_method_meta(tester) -> None: def test_bad_name(tester) -> None: # Create an ExecuTorch program from ModuleAdd. + # pyre-fixme[16]: Callable `make_test` has no attribute `wrapper`. exported_program, inputs = create_program(ModuleAdd()) # Use pybindings to load and execute the program.