Skip to content

Commit 71e26e1

Browse files
committed
MINIFICPP-2724 Add MinifiStatus return type to C api function that might fail
1 parent 3dbdb93 commit 71e26e1

15 files changed

Lines changed: 71 additions & 70 deletions

File tree

extension-framework/cpp-extension-lib/include/api/core/ProcessContext.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ class ProcessContext {
3737

3838
bool hasNonEmptyProperty(std::string_view name) const;
3939

40-
std::string getProcessorName() const;
41-
4240
private:
4341
MinifiProcessContext* impl_;
4442
};

extension-framework/cpp-extension-lib/include/api/utils/ProcessorConfigUtils.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,37 +33,37 @@ namespace org::apache::nifi::minifi::api::utils {
3333

3434
inline std::string parseProperty(const core::ProcessContext& ctx, const minifi::core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
3535
return ctx.getProperty(property.name, flow_file)
36-
| minifi::utils::orThrow(fmt::format("Expected valid value from \"{}::{}\"", ctx.getProcessorName(), property.name));
36+
| minifi::utils::orThrow(fmt::format("Expected valid value from \"{}\"", property.name));
3737
}
3838

3939
inline bool parseBoolProperty(const core::ProcessContext& ctx, const minifi::core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
4040
return ctx.getProperty(property.name, flow_file)
4141
| minifi::utils::andThen(parsing::parseBool)
42-
| minifi::utils::orThrow(fmt::format("Expected parsable bool from \"{}::{}\"", ctx.getProcessorName(), property.name));
42+
| minifi::utils::orThrow(fmt::format("Expected parsable bool from \"{}\"", property.name));
4343
}
4444

4545
inline uint64_t parseU64Property(const core::ProcessContext& ctx, const minifi::core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
4646
return ctx.getProperty(property.name, flow_file)
4747
| minifi::utils::andThen(parsing::parseIntegral<uint64_t>)
48-
| minifi::utils::orThrow(fmt::format("Expected parsable uint64_t from \"{}::{}\"", ctx.getProcessorName(), property.name));
48+
| minifi::utils::orThrow(fmt::format("Expected parsable uint64_t from \"{}\"", property.name));
4949
}
5050

5151
inline int64_t parseI64Property(const core::ProcessContext& ctx, const minifi::core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
5252
return ctx.getProperty(property.name, flow_file)
5353
| minifi::utils::andThen(parsing::parseIntegral<int64_t>)
54-
| minifi::utils::orThrow(fmt::format("Expected parsable int64_t from \"{}::{}\"", ctx.getProcessorName(), property.name));
54+
| minifi::utils::orThrow(fmt::format("Expected parsable int64_t from \"{}\"", property.name));
5555
}
5656

5757
inline std::chrono::milliseconds parseDurationProperty(const core::ProcessContext& ctx, const minifi::core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
5858
return ctx.getProperty(property.name, flow_file)
5959
| minifi::utils::andThen(parsing::parseDuration<std::chrono::milliseconds>)
60-
| minifi::utils::orThrow(fmt::format("Expected parsable duration from \"{}::{}\"", ctx.getProcessorName(), property.name));
60+
| minifi::utils::orThrow(fmt::format("Expected parsable duration from \"{}\"", property.name));
6161
}
6262

6363
inline uint64_t parseDataSizeProperty(const core::ProcessContext& ctx, const minifi::core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
6464
return ctx.getProperty(property.name, flow_file)
6565
| minifi::utils::andThen(parsing::parseDataSize)
66-
| minifi::utils::orThrow(fmt::format("Expected parsable data size from \"{}::{}\"", ctx.getProcessorName(), property.name));
66+
| minifi::utils::orThrow(fmt::format("Expected parsable data size from \"{}\"", property.name));
6767
}
6868

6969
inline std::optional<std::string> parseOptionalProperty(const core::ProcessContext& ctx, const minifi::core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
@@ -74,7 +74,7 @@ inline std::optional<std::string> parseOptionalProperty(const core::ProcessConte
7474
inline std::optional<bool> parseOptionalBoolProperty(const core::ProcessContext& ctx, const minifi::core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
7575
if (const auto property_str = ctx.getProperty(property.name, flow_file)) {
7676
return parsing::parseBool(*property_str)
77-
| minifi::utils::orThrow(fmt::format("Expected parsable bool from \"{}::{}\"", ctx.getProcessorName(), property.name));
77+
| minifi::utils::orThrow(fmt::format("Expected parsable bool from \"{}\"", property.name));
7878
}
7979
return std::nullopt;
8080
}
@@ -85,7 +85,7 @@ inline std::optional<uint64_t> parseOptionalU64Property(const core::ProcessConte
8585
return std::nullopt;
8686
}
8787
return parsing::parseIntegral<uint64_t>(*property_str)
88-
| minifi::utils::orThrow(fmt::format("Expected parsable uint64_t from \"{}::{}\"", ctx.getProcessorName(), property.name));
88+
| minifi::utils::orThrow(fmt::format("Expected parsable uint64_t from \"{}\"", property.name));
8989
}
9090

9191
return std::nullopt;
@@ -97,7 +97,7 @@ inline std::optional<int64_t> parseOptionalI64Property(const core::ProcessContex
9797
return std::nullopt;
9898
}
9999
return parsing::parseIntegral<int64_t>(*property_str)
100-
| minifi::utils::orThrow(fmt::format("Expected parsable int64_t from \"{}::{}\"", ctx.getProcessorName(), property.name));
100+
| minifi::utils::orThrow(fmt::format("Expected parsable int64_t from \"{}\"", property.name));
101101
}
102102

103103
return std::nullopt;
@@ -111,7 +111,7 @@ inline std::optional<std::chrono::milliseconds> parseOptionalDurationProperty(co
111111
return std::nullopt;
112112
}
113113
return parsing::parseDuration(*property_str)
114-
| minifi::utils::orThrow(fmt::format("Expected parsable duration from \"{}::{}\"", ctx.getProcessorName(), property.name));
114+
| minifi::utils::orThrow(fmt::format("Expected parsable duration from \"{}\"", property.name));
115115
}
116116

117117
return std::nullopt;
@@ -123,7 +123,7 @@ inline std::optional<uint64_t> parseOptionalDataSizeProperty(const core::Process
123123
return std::nullopt;
124124
}
125125
return parsing::parseDataSize(*property_str)
126-
| minifi::utils::orThrow(fmt::format("Expected parsable data size from \"{}::{}\"", ctx.getProcessorName(), property.name));
126+
| minifi::utils::orThrow(fmt::format("Expected parsable data size from \"{}\"", property.name));
127127
}
128128

129129
return std::nullopt;
@@ -135,7 +135,7 @@ inline std::optional<float> parseOptionalFloatProperty(const core::ProcessContex
135135
return std::nullopt;
136136
}
137137
return parsing::parseFloat(*property_str)
138-
| minifi::utils::orThrow(fmt::format("Expected parsable float from {}::{}", ctx.getProcessorName(), property.name));
138+
| minifi::utils::orThrow(fmt::format("Expected parsable float from \"{}\"", property.name));
139139
}
140140
return std::nullopt;
141141
}

extension-framework/cpp-extension-lib/src/core/ProcessContext.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,4 @@ bool ProcessContext::hasNonEmptyProperty(std::string_view name) const {
3838
return MinifiProcessContextHasNonEmptyProperty(impl_, utils::toStringView(name));
3939
}
4040

41-
std::string ProcessContext::getProcessorName() const {
42-
std::string result;
43-
MinifiProcessContextGetProcessorName(impl_, [] (void* data, MinifiStringView name) {
44-
*static_cast<std::string*>(data) = std::string(name.data, name.length);
45-
}, &result);
46-
return result;
47-
}
48-
49-
50-
5141
} // namespace org::apache::nifi::minifi::api::core

extension-framework/cpp-extension-lib/src/core/ProcessSession.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,15 @@ FlowFile ProcessSession::create(const FlowFile* parent) {
7979

8080
void ProcessSession::transfer(FlowFile ff, const minifi::core::Relationship& relationship) {
8181
const auto rel_name = relationship.getName();
82-
MinifiProcessSessionTransfer(impl_, ff.release(), utils::toStringView(rel_name));
82+
if (MINIFI_STATUS_SUCCESS != MinifiProcessSessionTransfer(impl_, ff.release(), utils::toStringView(rel_name))) {
83+
throw minifi::Exception(minifi::FILE_OPERATION_EXCEPTION, "Failed to transfer flowfile");
84+
}
8385
}
8486

8587
void ProcessSession::remove(FlowFile ff) {
86-
MinifiProcessSessionRemove(impl_, ff.release());
88+
if (MINIFI_STATUS_SUCCESS != MinifiProcessSessionRemove(impl_, ff.release())) {
89+
throw minifi::Exception(minifi::FILE_OPERATION_EXCEPTION, "Failed to remove flowfile");
90+
}
8791
}
8892

8993
void ProcessSession::write(FlowFile& flow_file, const io::OutputStreamCallback& callback) {
@@ -104,13 +108,17 @@ void ProcessSession::read(FlowFile& flow_file, const io::InputStreamCallback& ca
104108
}
105109
}
106110

107-
void ProcessSession::setAttribute(FlowFile& ff, std::string_view key, std::string value) { // NOLINT(performance-unnecessary-value-param)
108-
MinifiStringView value_ref = utils::toStringView(value);
109-
MinifiFlowFileSetAttribute(impl_, ff.get(), utils::toStringView(key), &value_ref);
111+
void ProcessSession::setAttribute(FlowFile& ff, const std::string_view key, std::string value) { // NOLINT(performance-unnecessary-value-param)
112+
const MinifiStringView value_ref = utils::toStringView(value);
113+
if (MINIFI_STATUS_SUCCESS != MinifiFlowFileSetAttribute(impl_, ff.get(), utils::toStringView(key), &value_ref)) {
114+
throw minifi::Exception(minifi::FILE_OPERATION_EXCEPTION, "Failed to set attribute");
115+
}
110116
}
111117

112-
void ProcessSession::removeAttribute(FlowFile& ff, std::string_view key) {
113-
MinifiFlowFileSetAttribute(impl_, ff.get(), utils::toStringView(key), nullptr);
118+
void ProcessSession::removeAttribute(FlowFile& ff, const std::string_view key) {
119+
if (MINIFI_STATUS_SUCCESS != MinifiFlowFileSetAttribute(impl_, ff.get(), utils::toStringView(key), nullptr)) {
120+
throw minifi::Exception(minifi::FILE_OPERATION_EXCEPTION, "Failed to remove attribute");
121+
}
114122
}
115123

116124
std::optional<std::string> ProcessSession::getAttribute(FlowFile& ff, std::string_view key) {

extension-framework/include/utils/ProcessorConfigUtils.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,37 @@ namespace org::apache::nifi::minifi::utils {
3434

3535
inline std::string parseProperty(const core::ProcessContext& ctx, const core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
3636
return ctx.getProperty(property.name, flow_file)
37-
| orThrow(fmt::format("Expected valid value from \"{}::{}\"", ctx.getProcessorInfo().getName(), property.name));
37+
| orThrow(fmt::format("Expected valid value from \"{}\"", property.name));
3838
}
3939

4040
inline bool parseBoolProperty(const core::ProcessContext& ctx, const core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
4141
return ctx.getProperty(property.name, flow_file)
4242
| andThen(parsing::parseBool)
43-
| orThrow(fmt::format("Expected parsable bool from \"{}::{}\"", ctx.getProcessorInfo().getName(), property.name));
43+
| orThrow(fmt::format("Expected parsable bool from \"{}\"", property.name));
4444
}
4545

4646
inline uint64_t parseU64Property(const core::ProcessContext& ctx, const core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
4747
return ctx.getProperty(property.name, flow_file)
4848
| andThen(parsing::parseIntegral<uint64_t>)
49-
| orThrow(fmt::format("Expected parsable uint64_t from \"{}::{}\"", ctx.getProcessorInfo().getName(), property.name));
49+
| orThrow(fmt::format("Expected parsable uint64_t from \"{}\"", property.name));
5050
}
5151

5252
inline int64_t parseI64Property(const core::ProcessContext& ctx, const core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
5353
return ctx.getProperty(property.name, flow_file)
5454
| andThen(parsing::parseIntegral<int64_t>)
55-
| orThrow(fmt::format("Expected parsable int64_t from \"{}::{}\"", ctx.getProcessorInfo().getName(), property.name));
55+
| orThrow(fmt::format("Expected parsable int64_t from \"{}\"", property.name));
5656
}
5757

5858
inline std::chrono::milliseconds parseDurationProperty(const core::ProcessContext& ctx, const core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
5959
return ctx.getProperty(property.name, flow_file)
6060
| andThen(parsing::parseDuration<std::chrono::milliseconds>)
61-
| orThrow(fmt::format("Expected parsable duration from \"{}::{}\"", ctx.getProcessorInfo().getName(), property.name));
61+
| orThrow(fmt::format("Expected parsable duration from \"{}\"", property.name));
6262
}
6363

6464
inline uint64_t parseDataSizeProperty(const core::ProcessContext& ctx, const core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
6565
return ctx.getProperty(property.name, flow_file)
6666
| andThen(parsing::parseDataSize)
67-
| orThrow(fmt::format("Expected parsable data size from \"{}::{}\"", ctx.getProcessorInfo().getName(), property.name));
67+
| orThrow(fmt::format("Expected parsable data size from \"{}\"", property.name));
6868
}
6969

7070
inline std::optional<std::string> parseOptionalProperty(const core::ProcessContext& ctx, const core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
@@ -75,7 +75,7 @@ inline std::optional<std::string> parseOptionalProperty(const core::ProcessConte
7575
inline std::optional<bool> parseOptionalBoolProperty(const core::ProcessContext& ctx, const core::PropertyReference& property, const core::FlowFile* flow_file = nullptr) {
7676
if (const auto property_str = ctx.getProperty(property.name, flow_file)) {
7777
return parsing::parseBool(*property_str)
78-
| utils::orThrow(fmt::format("Expected parsable bool from \"{}::{}\"", ctx.getProcessorInfo().getName(), property.name));
78+
| utils::orThrow(fmt::format("Expected parsable bool from \"{}\"", property.name));
7979
}
8080
return std::nullopt;
8181
}
@@ -86,7 +86,7 @@ inline std::optional<uint64_t> parseOptionalU64Property(const core::ProcessConte
8686
return std::nullopt;
8787
}
8888
return parsing::parseIntegral<uint64_t>(*property_str)
89-
| utils::orThrow(fmt::format("Expected parsable uint64_t from \"{}::{}\"", ctx.getProcessorInfo().getName(), property.name));
89+
| utils::orThrow(fmt::format("Expected parsable uint64_t from \"{}\"", property.name));
9090
}
9191

9292
return std::nullopt;
@@ -98,7 +98,7 @@ inline std::optional<int64_t> parseOptionalI64Property(const core::ProcessContex
9898
return std::nullopt;
9999
}
100100
return parsing::parseIntegral<int64_t>(*property_str)
101-
| utils::orThrow(fmt::format("Expected parsable int64_t from \"{}::{}\"", ctx.getProcessorInfo().getName(), property.name));
101+
| utils::orThrow(fmt::format("Expected parsable int64_t from \"{}\"", property.name));
102102
}
103103

104104
return std::nullopt;
@@ -110,7 +110,7 @@ inline std::optional<std::chrono::milliseconds> parseOptionalDurationProperty(co
110110
return std::nullopt;
111111
}
112112
return parsing::parseDuration(*property_str)
113-
| utils::orThrow(fmt::format("Expected parsable duration from \"{}::{}\"", ctx.getProcessorInfo().getName(), property.name));
113+
| utils::orThrow(fmt::format("Expected parsable duration from \"{}\"", property.name));
114114
}
115115

116116
return std::nullopt;
@@ -122,7 +122,7 @@ inline std::optional<uint64_t> parseOptionalDataSizeProperty(const core::Process
122122
return std::nullopt;
123123
}
124124
return parsing::parseDataSize(*property_str)
125-
| utils::orThrow(fmt::format("Expected parsable data size from \"{}::{}\"", ctx.getProcessorInfo().getName(), property.name));
125+
| utils::orThrow(fmt::format("Expected parsable data size from \"{}\"", property.name));
126126
}
127127

128128
return std::nullopt;
@@ -134,7 +134,7 @@ inline std::optional<float> parseOptionalFloatProperty(const core::ProcessContex
134134
return std::nullopt;
135135
}
136136
return parsing::parseFloat(*property_str)
137-
| utils::orThrow(fmt::format("Expected parsable float from {}::{}", ctx.getProcessorInfo().getName(), property.name));
137+
| utils::orThrow(fmt::format("Expected parsable float from \"{}\"", property.name));
138138
}
139139
return std::nullopt;
140140
}

extensions/azure/tests/FetchAzureDataLakeStorageTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ TEST_CASE_METHOD(FetchAzureDataLakeStorageTestsFixture, "Valid Number of Retries
157157

158158
TEST_CASE_METHOD(FetchAzureDataLakeStorageTestsFixture, "Invalid Number of Retries is set via EL", "[azureDataLakeStorageFetch]") {
159159
plan_->setProperty(azure_data_lake_storage_, minifi::azure::processors::FetchAzureDataLakeStorage::NumberOfRetries, "${literal(\"asd\")}");
160-
REQUIRE_THROWS_WITH(test_controller_.runSession(plan_, true), "Expected parsable uint64_t from \"AzureDataLakeStorageProcessor::Number of Retries\", but got GeneralParsingError (Parsing Error:0)");
160+
REQUIRE_THROWS_WITH(test_controller_.runSession(plan_, true), "Expected parsable uint64_t from \"Number of Retries\", but got GeneralParsingError (Parsing Error:0)");
161161
CHECK_FALSE(mock_data_lake_storage_client_ptr_->getPassedFetchParams().number_of_retries);
162162
}
163163

extensions/llamacpp/tests/RunLlamaCppInferenceTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ TEST_CASE("Invalid values for optional double type properties throw exception")
229229

230230
REQUIRE_THROWS(controller.trigger(minifi::test::InputFlowFileData{.content = "42", .attributes = {}}));
231231
CHECK(minifi::test::utils::verifyLogLinePresenceInPollTime(1s,
232-
fmt::format("Expected parsable float from RunLlamaCppInference::{}, but got GeneralParsingError (Parsing Error:0)", property_name)));
232+
fmt::format("Expected parsable float from \"{}\", but got GeneralParsingError (Parsing Error:0)", property_name)));
233233
}
234234

235235
TEST_CASE("Top K property empty and invalid values are handled properly") {
@@ -252,7 +252,7 @@ TEST_CASE("Top K property empty and invalid values are handled properly") {
252252
REQUIRE(controller.getProcessor()->setProperty(processors::RunLlamaCppInference::TopK.name, "invalid_value"));
253253
REQUIRE_THROWS(controller.trigger(minifi::test::InputFlowFileData{.content = "42", .attributes = {}}));
254254
CHECK(minifi::test::utils::verifyLogLinePresenceInPollTime(1s,
255-
"Expected parsable int64_t from \"RunLlamaCppInference::Top K\", but got GeneralParsingError (Parsing Error:0)"));
255+
"Expected parsable int64_t from \"Top K\", but got GeneralParsingError (Parsing Error:0)"));
256256
}
257257
}
258258

extensions/mqtt/tests/ConsumeMQTTTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ using namespace std::literals::chrono_literals;
120120
TEST_CASE_METHOD(ConsumeMqttTestFixture, "ConsumeMQTTTest_EmptyTopic", "[consumeMQTTTest]") {
121121
REQUIRE(test_controller_.plan->setProperty(consume_mqtt_processor_, minifi::processors::AbstractMQTTProcessor::BrokerURI.name, "127.0.0.1:1883"));
122122
REQUIRE_THROWS_WITH(test_controller_.plan->scheduleProcessor(consume_mqtt_processor_),
123-
Catch::Matchers::EndsWith("Expected valid value from \"TestConsumeMQTTProcessor::Topic\", but got PropertyNotSet (Property Error:2)"));
123+
Catch::Matchers::EndsWith("Expected valid value from \"Topic\", but got PropertyNotSet (Property Error:2)"));
124124
}
125125

126126
TEST_CASE_METHOD(ConsumeMqttTestFixture, "ConsumeMQTTTest_EmptyBrokerURI", "[consumeMQTTTest]") {
127127
REQUIRE(test_controller_.plan->setProperty(consume_mqtt_processor_, minifi::processors::ConsumeMQTT::Topic.name, "mytopic"));
128128
REQUIRE_THROWS_WITH(test_controller_.plan->scheduleProcessor(consume_mqtt_processor_),
129-
Catch::Matchers::EndsWith("Expected valid value from \"TestConsumeMQTTProcessor::Broker URI\", but got PropertyNotSet (Property Error:2)"));
129+
Catch::Matchers::EndsWith("Expected valid value from \"Broker URI\", but got PropertyNotSet (Property Error:2)"));
130130
}
131131

132132
TEST_CASE_METHOD(ConsumeMqttTestFixture, "ConsumeMQTTTest_DurableSessionWithID", "[consumeMQTTTest]") {

extensions/mqtt/tests/PublishMQTTTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ TEST_CASE_METHOD(PublishMQTTTestFixture, "PublishMQTTTest_EmptyTopic", "[publish
8080
TEST_CASE_METHOD(PublishMQTTTestFixture, "PublishMQTTTest_EmptyBrokerURI", "[publishMQTTTest]") {
8181
REQUIRE(test_controller_.plan->setProperty(publish_mqtt_processor_, minifi::processors::PublishMQTT::Topic.name, "mytopic"));
8282
REQUIRE_THROWS_WITH(test_controller_.plan->scheduleProcessor(publish_mqtt_processor_),
83-
Catch::Matchers::EndsWith("Expected valid value from \"TestPublishMQTTProcessor::Broker URI\", but got PropertyNotSet (Property Error:2)"));
83+
Catch::Matchers::EndsWith("Expected valid value from \"Broker URI\", but got PropertyNotSet (Property Error:2)"));
8484
}
8585

8686
TEST_CASE_METHOD(PublishMQTTTestFixture, "PublishMQTTTest_EmptyClientID_V_3", "[publishMQTTTest]") {

0 commit comments

Comments
 (0)