Skip to content

Commit fa6ad34

Browse files
committed
chore(validation,conditions): document errors and panics instead of allowing doc lints
1 parent ba28fa9 commit fa6ad34

10 files changed

Lines changed: 107 additions & 28 deletions

File tree

‎src/components/validation/mod.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,14 @@ fn get_validation_configuration_from_test_case_path(
441441
))
442442
}
443443

444+
/// Runs component validation for the test case data file at the given path.
445+
///
446+
/// # Panics
447+
///
448+
/// Panics if the path does not exist, if the path does not map to a validatable component (it
449+
/// must end in `<sources|transforms|sinks>/<component name>.yaml`), if the Tokio runtime cannot be
450+
/// built, if the validation run returns an error, or if any validator reports a failure.
444451
#[cfg(feature = "component-validation-runner")]
445-
// https://github.com/vectordotdev/vector/issues/23659
446-
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
447452
pub fn validate_component(test_case_data_path: std::path::PathBuf) {
448453
assert!(
449454
test_case_data_path.exists(),

‎src/components/validation/resources/event.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,11 @@ impl From<RawTestEvent> for TestEvent {
161161
}
162162
}
163163

164-
// https://github.com/vectordotdev/vector/issues/23659
165-
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
164+
/// Encodes a test event into `buf`, using an alternate encoder for events meant to fail encoding.
165+
///
166+
/// # Panics
167+
///
168+
/// Panics if the event cannot be encoded with the selected encoder.
166169
pub fn encode_test_event(
167170
encoder: &mut Encoder<encoding::Framer>,
168171
buf: &mut BytesMut,

‎src/components/validation/resources/http.rs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,18 @@ impl HttpResourceConfig {
8787
}
8888
}
8989

90+
/// Spawns this resource as the output for a sink.
91+
///
92+
/// # Errors
93+
///
94+
/// Returns an error if the decoder for the resource codec cannot be built.
95+
///
96+
/// # Panics
97+
///
98+
/// Panics if the resource direction is `Pull`, which is not implemented, or if the URI host is
99+
/// missing or not an IP address. Panics if the codec uses a serializer that has no matching
100+
/// deserializer for validation.
90101
// https://github.com/vectordotdev/vector/issues/23659
91-
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
92102
#[allow(
93103
clippy::needless_pass_by_value,
94104
reason = "Preserve ownership and drop timing"

‎src/components/validation/resources/mod.rs‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,13 @@ impl ResourceCodec {
7575
///
7676
/// The encoder is generated as an inverse to the input codec: if a decoding configuration was
7777
/// given, we generate an encoder that satisfies that decoding configuration, and vice versa.
78+
///
79+
/// # Panics
80+
///
81+
/// Panics if the serializer fails to build, or if the decoding configuration uses a
82+
/// deserializer (`influxdb`, `vrl`) or framing (`octet_counting`, `chunked_gelf`) that has no
83+
/// encoding equivalent.
7884
#[must_use]
79-
// https://github.com/vectordotdev/vector/issues/23659
80-
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
8185
pub fn into_encoder(&self) -> Encoder<encoding::Framer> {
8286
let (framer, serializer) = match self {
8387
Self::Encoding(config) => (
@@ -109,8 +113,16 @@ impl ResourceCodec {
109113
///
110114
/// The decoder is generated as an inverse to the input codec: if an encoding configuration was
111115
/// given, we generate a decoder that satisfies that encoding configuration, and vice versa.
112-
// https://github.com/vectordotdev/vector/issues/23659
113-
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
116+
///
117+
/// # Errors
118+
///
119+
/// Returns an error if the deserializer cannot be built, such as when a Protobuf descriptor
120+
/// file cannot be loaded.
121+
///
122+
/// # Panics
123+
///
124+
/// Panics if the encoding configuration uses a serializer that has no decoding equivalent
125+
/// (`avro`, `cef`, `csv`, `logfmt`, `otlp`, or `syslog`).
114126
pub fn into_decoder(&self, log_namespace: LogNamespace) -> vector_lib::Result<Decoder> {
115127
let (framer, deserializer) = match self {
116128
Self::Decoding(config) => return config.build(),
@@ -397,8 +409,16 @@ impl ExternalResource {
397409
}
398410

399411
/// Spawns this resource for use as an output for a sink.
400-
// https://github.com/vectordotdev/vector/issues/23659
401-
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
412+
///
413+
/// # Errors
414+
///
415+
/// Returns an error if the decoder for the resource codec cannot be built.
416+
///
417+
/// # Panics
418+
///
419+
/// Panics if an HTTP resource uses the `Pull` direction, which is not implemented, or if its
420+
/// URI host is missing or not an IP address. Panics if the codec uses a serializer that has no
421+
/// matching deserializer for validation.
402422
pub fn spawn_as_output(
403423
self,
404424
output_tx: mpsc::Sender<Vec<Event>>,

‎src/components/validation/runner/config.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ pub struct TopologyBuilder {
2828

2929
impl TopologyBuilder {
3030
/// Creates a component topology for the given component configuration.
31-
// https://github.com/vectordotdev/vector/issues/23659
32-
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
31+
///
32+
/// # Errors
33+
///
34+
/// Returns an error if the configuration has no component configuration for `config_name`.
3335
pub fn from_configuration(
3436
configuration: &ValidationConfiguration,
3537
config_name: Option<&String>,

‎src/components/validation/runner/mod.rs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,22 @@ impl Runner {
208208
}
209209
}
210210

211+
/// Runs every test case for the configured component and collects the validator results.
212+
///
213+
/// # Errors
214+
///
215+
/// Returns an error if the test case file cannot be opened or deserialized, if a test case
216+
/// names a component configuration that does not exist, or if a sink's external resource
217+
/// fails to spawn (for example, because its decoder cannot be built).
218+
///
219+
/// # Panics
220+
///
221+
/// Panics if a source or sink has no external resource, if the input or output driver task
222+
/// panics, or if the generated topology configuration fails to build. Spawning external
223+
/// resources and drivers can also panic on unsupported codecs, framings, or resource
224+
/// directions, and on invalid resource URIs.
211225
#[allow(clippy::print_stdout)]
212226
// https://github.com/vectordotdev/vector/issues/23659
213-
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
214-
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
215227
#[allow(clippy::too_many_lines, reason = "Preserve existing control flow")]
216228
pub async fn run_validation(self) -> Result<Vec<RunnerResults>, vector_lib::Error> {
217229
// Initialize our test environment.

‎src/components/validation/util.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ impl GrpcAddress {
2525
/// Gets the fully-qualified endpoint address.
2626
///
2727
/// This is a URI in the form of `http://<socket address>/`. The scheme and path are hard-coded.
28+
///
29+
/// # Panics
30+
///
31+
/// Panics if the socket address does not form a valid URI authority, which should not happen
32+
/// for any `SocketAddr`.
2833
#[must_use]
29-
// https://github.com/vectordotdev/vector/issues/23659
30-
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
3134
pub fn as_uri(&self) -> Uri {
3235
let addr_str = self.addr.to_string();
3336
Uri::builder()

‎src/components/validation/validators/mod.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ pub trait Validator {
1919
///
2020
/// Additionally, all telemetry events received for the component for the validation run are
2121
/// provided as well.
22-
// https://github.com/vectordotdev/vector/issues/23659
23-
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
22+
///
23+
/// # Errors
24+
///
25+
/// Implementations return an error containing the failure messages if the inputs, outputs,
26+
/// telemetry events, or runner metrics do not satisfy the validator's requirements for the
27+
/// given component type and test case expectation.
2428
fn check_validation(
2529
&self,
2630
component_type: ComponentType,

‎src/conditions/datadog_search.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ impl Default for DatadogSearchConfig {
3333
}
3434

3535
impl DatadogSearchConfig {
36-
// https://github.com/vectordotdev/vector/issues/23659
37-
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
36+
/// Builds a log event matcher from the configured query.
37+
///
38+
/// # Errors
39+
///
40+
/// Returns an error if a field referenced in the query cannot be parsed as a path.
3841
pub fn build_matcher(&self) -> crate::Result<Box<dyn Matcher<LogEvent>>> {
3942
Ok(build_matcher(&self.source, &EventFilter)?)
4043
}

‎src/conditions/mod.rs‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,12 @@ pub enum ConditionConfig {
120120
}
121121

122122
impl ConditionConfig {
123-
// https://github.com/vectordotdev/vector/issues/23659
124-
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
123+
/// Builds the configured condition.
124+
///
125+
/// # Errors
126+
///
127+
/// Returns an error if a VRL condition fails to compile or does not return a boolean, or if
128+
/// a Datadog Search query contains a field that cannot be parsed as a path.
125129
pub fn build(
126130
&self,
127131
enrichment_tables: &vector_lib::enrichment::TableRegistry,
@@ -158,8 +162,12 @@ pub trait Conditional: std::fmt::Debug {
158162
}
159163

160164
pub trait ConditionalConfig: std::fmt::Debug + Send + Sync + dyn_clone::DynClone {
161-
// https://github.com/vectordotdev/vector/issues/23659
162-
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
165+
/// Builds the condition described by this configuration.
166+
///
167+
/// # Errors
168+
///
169+
/// Implementations return an error if the configuration cannot be turned into a usable
170+
/// condition, such as a source that fails to compile or parse.
163171
fn build(
164172
&self,
165173
enrichment_tables: &vector_lib::enrichment::TableRegistry,
@@ -200,12 +208,17 @@ pub enum AnyCondition {
200208
}
201209

202210
impl AnyCondition {
211+
/// Builds the condition, treating a plain string as a VRL boolean expression.
212+
///
213+
/// # Errors
214+
///
215+
/// Returns an error if a VRL condition fails to compile or does not return a boolean, or if
216+
/// a Datadog Search query contains a field that cannot be parsed as a path.
203217
// https://github.com/vectordotdev/vector/issues/23659
204218
#[allow(
205219
clippy::default_trait_access,
206220
reason = "Preserve inferred default types"
207221
)]
208-
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
209222
pub fn build(
210223
&self,
211224
enrichment_tables: &vector_lib::enrichment::TableRegistry,
@@ -223,8 +236,12 @@ impl AnyCondition {
223236
}
224237
}
225238

226-
// https://github.com/vectordotdev/vector/issues/23659
227-
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
239+
/// Checks that the condition can be built, discarding the result.
240+
///
241+
/// # Errors
242+
///
243+
/// Returns an error if a VRL condition fails to compile or does not return a boolean, or if
244+
/// a Datadog Search query contains a field that cannot be parsed as a path.
228245
pub fn validate(
229246
&self,
230247
enrichment_tables: &vector_lib::enrichment::TableRegistry,

0 commit comments

Comments
 (0)