This is an automated email from the ASF dual-hosted git repository. szaszm pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit 634016bbe0c934678bd9f09c4a5c10e31fd3d4a8 Author: Ferenc Gerlits <[email protected]> AuthorDate: Mon Jan 20 16:54:41 2025 +0100 MINIFICPP-2499 Do not log errors when loading Python helper files Closes #1913 Signed-off-by: Marton Szasz <[email protected]> --- extensions/python/ExecutePythonProcessor.cpp | 2 ++ extensions/python/PythonCreator.h | 4 +++- extensions/python/PythonScriptEngine.cpp | 2 +- extensions/python/PythonScriptException.h | 7 +++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/extensions/python/ExecutePythonProcessor.cpp b/extensions/python/ExecutePythonProcessor.cpp index 7beca34d4..3cc282514 100644 --- a/extensions/python/ExecutePythonProcessor.cpp +++ b/extensions/python/ExecutePythonProcessor.cpp @@ -69,6 +69,8 @@ void ExecutePythonProcessor::initalizeThroughScriptEngine() { python_script_engine_->describe(this); python_script_engine_->onInitialize(this); processor_initialized_ = true; + } catch (const PythonScriptWarning&) { + throw; } catch (const std::exception& e) { std::string python_processor_name = python_class_name_ ? *python_class_name_ : script_file_path_; logger_->log_error("Failed to initialize python processor '{}' due to error: {}", python_processor_name, e.what()); diff --git a/extensions/python/PythonCreator.h b/extensions/python/PythonCreator.h index dce65b356..ad2e5164f 100644 --- a/extensions/python/PythonCreator.h +++ b/extensions/python/PythonCreator.h @@ -97,8 +97,10 @@ class PythonCreator : public minifi::core::CoreComponent { registered_classes_.push_back(class_name); try { registerScriptDescription(class_name, full_name, path, script_name.string()); + } catch (const PythonScriptWarning &warning) { + logger_->log_info("Could not process {}.py: {} -- if this is a helper file, then this is OK", script_name, warning.what()); } catch (const std::exception &err) { - logger_->log_error("Cannot load {}: {}", script_name, err.what()); + logger_->log_error("Could not process {}.py: {}", script_name, err.what()); } } } diff --git a/extensions/python/PythonScriptEngine.cpp b/extensions/python/PythonScriptEngine.cpp index 60e661b05..e68ba022f 100644 --- a/extensions/python/PythonScriptEngine.cpp +++ b/extensions/python/PythonScriptEngine.cpp @@ -200,7 +200,7 @@ void PythonScriptEngine::initializeProcessorObject(const std::string& python_cla throw PythonScriptException("Could not bind 'REL_ORIGINAL' object to '" + python_class_name + "' python processor object"); } } else { - throw PythonScriptException("No python class '" + python_class_name + "' was found!"); + throw PythonScriptWarning("No Python class '" + python_class_name + "' was found"); } } diff --git a/extensions/python/PythonScriptException.h b/extensions/python/PythonScriptException.h index 4ba0ebf87..0a0728121 100644 --- a/extensions/python/PythonScriptException.h +++ b/extensions/python/PythonScriptException.h @@ -25,8 +25,15 @@ #include <stdexcept> namespace org::apache::nifi::minifi::extensions::python { + +class PythonScriptWarning : public std::runtime_error { + public: + explicit PythonScriptWarning(const std::string& error) : std::runtime_error(error) {} +}; + class PythonScriptException : public std::runtime_error { public: explicit PythonScriptException(const std::string& error) : std::runtime_error(error) {} }; + } // namespace org::apache::nifi::minifi::extensions::python
