@@ -22,7 +22,7 @@ use once_cell::sync::Lazy;
22
22
use regex:: Regex ;
23
23
use serde:: { Deserialize , Deserializer } ;
24
24
use serde_json:: { Map , Value } ;
25
- use tracing:: { error, warn } ;
25
+ use tracing:: error;
26
26
27
27
/// Predefined JSON with known textual logging formats
28
28
const FORMATS_JSON : & str = include_str ! ( "../../../resources/formats.json" ) ;
@@ -32,8 +32,12 @@ pub static KNOWN_SCHEMA_LIST: Lazy<EventProcessor> =
32
32
Lazy :: new ( || EventProcessor :: new ( FORMATS_JSON ) ) ;
33
33
34
34
#[ derive( Debug , thiserror:: Error ) ]
35
- #[ error( "Event is not in the expected text/JSON format for {0}" ) ]
36
- pub struct Unacceptable ( String ) ;
35
+ pub enum Error {
36
+ #[ error( "Event is not in the expected text/JSON format for {0}" ) ]
37
+ Unacceptable ( String ) ,
38
+ #[ error( "Unknown log format: {0}" ) ]
39
+ Unknown ( String ) ,
40
+ }
37
41
38
42
/// Deserializes a string pattern into a compiled Regex
39
43
/// NOTE: we only warn if the pattern doesn't compile
@@ -178,10 +182,9 @@ impl EventProcessor {
178
182
json : & mut Value ,
179
183
log_source : & str ,
180
184
extract_log : Option < & str > ,
181
- ) -> Result < HashSet < String > , Unacceptable > {
185
+ ) -> Result < HashSet < String > , Error > {
182
186
let Some ( schema) = self . schema_definitions . get ( log_source) else {
183
- warn ! ( "Unknown log format: {log_source}" ) ;
184
- return Ok ( HashSet :: new ( ) ) ;
187
+ return Err ( Error :: Unknown ( log_source. to_owned ( ) ) ) ;
185
188
} ;
186
189
187
190
let mut fields = HashSet :: new ( ) ;
@@ -194,15 +197,15 @@ impl EventProcessor {
194
197
if let Some ( known_fields) = schema. check_or_extract ( event, extract_log) {
195
198
fields. extend ( known_fields) ;
196
199
} else {
197
- return Err ( Unacceptable ( log_source. to_owned ( ) ) ) ;
200
+ return Err ( Error :: Unacceptable ( log_source. to_owned ( ) ) ) ;
198
201
}
199
202
}
200
203
}
201
204
Value :: Object ( event) => {
202
205
if let Some ( known_fields) = schema. check_or_extract ( event, extract_log) {
203
206
return Ok ( known_fields) ;
204
207
} else {
205
- return Err ( Unacceptable ( log_source. to_owned ( ) ) ) ;
208
+ return Err ( Error :: Unacceptable ( log_source. to_owned ( ) ) ) ;
206
209
}
207
210
}
208
211
_ => unreachable ! ( "We don't accept events of the form: {json}" ) ,
0 commit comments