diff --git a/falco_plugin/src/plugin/base/wrappers.rs b/falco_plugin/src/plugin/base/wrappers.rs index 9fc01eac..7756ca46 100644 --- a/falco_plugin/src/plugin/base/wrappers.rs +++ b/falco_plugin/src/plugin/base/wrappers.rs @@ -58,8 +58,8 @@ pub unsafe extern "C" fn plugin_init( rc: *mut ss_plugin_rc, ) -> *mut falco_plugin_api::ss_plugin_t { let res = (|| -> Result<*mut PluginWrapper

, anyhow::Error> { - let init_input = - unsafe { init_input.as_ref() }.ok_or(anyhow::anyhow!("Got empty init_input"))?; + let init_input = unsafe { init_input.as_ref() } + .ok_or_else(|| anyhow::anyhow!("Got empty init_input"))?; let init_config = try_str_from_ptr(&init_input.config).context("Failed to get config string")?; diff --git a/falco_plugin/src/plugin/exported_tables/table.rs b/falco_plugin/src/plugin/exported_tables/table.rs index 1c7c0840..721bd77a 100644 --- a/falco_plugin/src/plugin/exported_tables/table.rs +++ b/falco_plugin/src/plugin/exported_tables/table.rs @@ -191,10 +191,9 @@ where let (type_id, index) = { (field.type_id, field.index) }; let value = unsafe { - DynamicFieldValue::from_data(value, type_id).ok_or(anyhow::anyhow!( - "Cannot store {:?} data (unsupported type)", - type_id - ))? + DynamicFieldValue::from_data(value, type_id).ok_or_else(|| { + anyhow::anyhow!("Cannot store {:?} data (unsupported type)", type_id) + })? }; entry.set(index, value) diff --git a/falco_plugin/src/plugin/listen/mod.rs b/falco_plugin/src/plugin/listen/mod.rs index ab908787..a29ca39a 100644 --- a/falco_plugin/src/plugin/listen/mod.rs +++ b/falco_plugin/src/plugin/listen/mod.rs @@ -44,7 +44,7 @@ impl CaptureListenInput { let input = unsafe { value .as_ref() - .ok_or(anyhow::anyhow!("Got null event parse input"))? + .ok_or_else(|| anyhow::anyhow!("Got null event parse input"))? }; let thread_pool = ThreadPool::try_from(input.owner, input.routine, last_error.clone())?; @@ -53,13 +53,13 @@ impl CaptureListenInput { input .table_reader_ext .as_ref() - .ok_or(anyhow::anyhow!("Got null reader vtable"))? + .ok_or_else(|| anyhow::anyhow!("Got null reader vtable"))? }; let writer = unsafe { input .table_writer_ext .as_ref() - .ok_or(anyhow::anyhow!("Got null writer vtable"))? + .ok_or_else(|| anyhow::anyhow!("Got null writer vtable"))? }; let reader = TableReader::try_from(reader, last_error.clone())?; diff --git a/falco_plugin/src/plugin/parse/mod.rs b/falco_plugin/src/plugin/parse/mod.rs index d72c8441..b22b4c56 100644 --- a/falco_plugin/src/plugin/parse/mod.rs +++ b/falco_plugin/src/plugin/parse/mod.rs @@ -78,20 +78,20 @@ impl ParseInput { let input = unsafe { value .as_ref() - .ok_or(anyhow::anyhow!("Got null event parse input"))? + .ok_or_else(|| anyhow::anyhow!("Got null event parse input"))? }; let reader = unsafe { input .table_reader_ext .as_ref() - .ok_or(anyhow::anyhow!("Got null reader vtable"))? + .ok_or_else(|| anyhow::anyhow!("Got null reader vtable"))? }; let writer = unsafe { input .table_writer_ext .as_ref() - .ok_or(anyhow::anyhow!("Got null writer vtable"))? + .ok_or_else(|| anyhow::anyhow!("Got null writer vtable"))? }; let reader = TableReader::try_from(reader, last_error.clone())?; diff --git a/falco_plugin/src/plugin/tables/entry/mod.rs b/falco_plugin/src/plugin/tables/entry/mod.rs index 6fb1adeb..c960ea2b 100644 --- a/falco_plugin/src/plugin/tables/entry/mod.rs +++ b/falco_plugin/src/plugin/tables/entry/mod.rs @@ -53,7 +53,7 @@ impl Entry { unsafe { self.raw_entry .read_field_with_assoc::(reader, field.field.field, &field.field.assoc_data) - .ok_or(anyhow::anyhow!("Could not read field value")) + .ok_or_else(|| anyhow::anyhow!("Could not read field value")) .with_last_error(&reader.last_error) } } diff --git a/falco_plugin/src/plugin/tables/table/raw.rs b/falco_plugin/src/plugin/tables/table/raw.rs index 3fa172f2..42bed727 100644 --- a/falco_plugin/src/plugin/tables/table/raw.rs +++ b/falco_plugin/src/plugin/tables/table/raw.rs @@ -61,7 +61,7 @@ impl RawTable { ); field .as_mut() - .ok_or(anyhow::anyhow!("Failed to get table field {:?}", name)) + .ok_or_else(|| anyhow::anyhow!("Failed to get table field {:?}", name)) .with_last_error(&tables_input.last_error)?; field }; @@ -93,7 +93,7 @@ impl RawTable { ); field .as_mut() - .ok_or(anyhow::anyhow!("Failed to add table field {:?}", name)) + .ok_or_else(|| anyhow::anyhow!("Failed to add table field {:?}", name)) .with_last_error(&tables_input.last_error)?; field }; diff --git a/falco_plugin_tests/tests/extract.rs b/falco_plugin_tests/tests/extract.rs index 25b1df02..c7a93bab 100644 --- a/falco_plugin_tests/tests/extract.rs +++ b/falco_plugin_tests/tests/extract.rs @@ -102,7 +102,7 @@ impl DummyPlugin { let payload = event .params .event_data - .ok_or(anyhow::anyhow!("no payload in event"))?; + .ok_or_else(|| anyhow::anyhow!("no payload in event"))?; let mut out = CString::default(); out.write_into(|w| w.write_all(payload))?; @@ -123,7 +123,7 @@ impl DummyPlugin { let payload = event .params .event_data - .ok_or(anyhow::anyhow!("no payload in event"))?; + .ok_or_else(|| anyhow::anyhow!("no payload in event"))?; let mut out = CString::default(); out.write_into(|w| w.write_all(payload))?; @@ -140,7 +140,7 @@ impl DummyPlugin { let payload = event .params .event_data - .ok_or(anyhow::anyhow!("no payload in event"))?; + .ok_or_else(|| anyhow::anyhow!("no payload in event"))?; let first_char = &payload[0..1]; let first_char = std::str::from_utf8(first_char)?; @@ -162,7 +162,7 @@ impl DummyPlugin { let payload = event .params .event_data - .ok_or(anyhow::anyhow!("no payload in event"))?; + .ok_or_else(|| anyhow::anyhow!("no payload in event"))?; let first_char = &payload[0..1]; let first_char = std::str::from_utf8(first_char)?; @@ -184,7 +184,7 @@ impl DummyPlugin { ExtractFieldRequestArg::None => event .params .event_data - .ok_or(anyhow::anyhow!("no payload in event"))?, + .ok_or_else(|| anyhow::anyhow!("no payload in event"))?, }; let first_char = &buf[0..1]; diff --git a/falco_plugin_tests/tests/parse.rs b/falco_plugin_tests/tests/parse.rs index 6a4ddc19..0e124a87 100644 --- a/falco_plugin_tests/tests/parse.rs +++ b/falco_plugin_tests/tests/parse.rs @@ -119,7 +119,7 @@ impl ParsePlugin for DummyPlugin { let payload = event .params .event_data - .ok_or(anyhow::anyhow!("no payload in event"))?; + .ok_or_else(|| anyhow::anyhow!("no payload in event"))?; let first_char = &payload[0..1]; let first_char = std::str::from_utf8(first_char)?; diff --git a/falco_plugin_tests/tests/parse_runtime.rs b/falco_plugin_tests/tests/parse_runtime.rs index 99fd0241..74202b26 100644 --- a/falco_plugin_tests/tests/parse_runtime.rs +++ b/falco_plugin_tests/tests/parse_runtime.rs @@ -118,7 +118,7 @@ impl ParsePlugin for DummyPlugin { let payload = event .params .event_data - .ok_or(anyhow::anyhow!("no payload in event"))?; + .ok_or_else(|| anyhow::anyhow!("no payload in event"))?; let first_char = &payload[0..1]; let first_char = std::str::from_utf8(first_char)?; diff --git a/falco_plugin_tests/tests/parse_table_api.rs b/falco_plugin_tests/tests/parse_table_api.rs index 479bbc48..ebd71780 100644 --- a/falco_plugin_tests/tests/parse_table_api.rs +++ b/falco_plugin_tests/tests/parse_table_api.rs @@ -136,7 +136,7 @@ impl ParsePlugin for DummyPlugin { let payload = event .params .event_data - .ok_or(anyhow::anyhow!("no payload in event"))?; + .ok_or_else(|| anyhow::anyhow!("no payload in event"))?; let first_char = &payload[0..1]; let first_char = std::str::from_utf8(first_char)?; diff --git a/falco_plugin_tests/tests/parse_table_nested.rs b/falco_plugin_tests/tests/parse_table_nested.rs index 145bb1dd..e007a59b 100644 --- a/falco_plugin_tests/tests/parse_table_nested.rs +++ b/falco_plugin_tests/tests/parse_table_nested.rs @@ -130,7 +130,7 @@ impl ParsePlugin for DummyPlugin { let payload = event .params .event_data - .ok_or(anyhow::anyhow!("no payload in event"))?; + .ok_or_else(|| anyhow::anyhow!("no payload in event"))?; let first_char = &payload[0..1]; let first_char = std::str::from_utf8(first_char)?;