Skip to content

Commit

Permalink
first attempt: use nonstd::expected (incomplete)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgerlits committed Jan 6, 2025
1 parent b194ce5 commit 33769b5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions extensions/python/ExecutePythonProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ void ExecutePythonProcessor::initalizeThroughScriptEngine() {
python_script_engine_->appendModulePaths(python_paths_);
python_script_engine_->setModuleAttributes(qualified_module_name_);
python_script_engine_->eval(script_to_exec_);
if (python_class_name_) {
python_script_engine_->initializeProcessorObject(*python_class_name_);
if (python_class_name_ && python_script_engine_->initializeProcessorObject(*python_class_name_)) {
python_script_engine_->describe(this);
python_script_engine_->onInitialize(this);
processor_initialized_ = true;
}
python_script_engine_->describe(this);
python_script_engine_->onInitialize(this);
processor_initialized_ = true;
} 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());
Expand Down
4 changes: 2 additions & 2 deletions extensions/python/PythonScriptEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void PythonScriptEngine::evaluateModuleImports() {
}
}

void PythonScriptEngine::initializeProcessorObject(const std::string& python_class_name) {
nonstd::expected<void, std::string> PythonScriptEngine::initializeProcessorObject(const std::string& python_class_name) {
GlobalInterpreterLock gil;
if (auto python_class = bindings_[python_class_name]) {
auto num_args = [&]() -> size_t {
Expand Down Expand Up @@ -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!");
return nonstd::make_unexpected(std::format("{} is not a Python class, skipping it", python_class_name));
}
}

Expand Down
2 changes: 1 addition & 1 deletion extensions/python/PythonScriptEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class PythonScriptEngine {
void onSchedule(core::ProcessContext& context);
void onTrigger(core::ProcessContext& context, core::ProcessSession& session);
void initialize(const core::Relationship& success, const core::Relationship& failure, const core::Relationship& original, const std::shared_ptr<core::logging::Logger>& logger);
void initializeProcessorObject(const std::string& python_class_name);
nonstd::expected<void, std::string> initializeProcessorObject(const std::string& python_class_name);
std::vector<core::Relationship> getCustomPythonRelationships();
void setModuleAttributes(const std::string& qualified_module_name);

Expand Down

0 comments on commit 33769b5

Please sign in to comment.