File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -195,11 +195,40 @@ impl ToDuckSQL for Expr {
195195 {
196196 format ! ( "{} {} {}" , a[ 0 ] , op, a[ 1 ] )
197197 } else {
198- unreachable ! ( )
198+ return Err ( Error :: InvalidOperator ( op . to_string ( ) ) ) ;
199199 }
200200 }
201201 }
202202 }
203203 } )
204204 }
205205}
206+
207+ #[ cfg( test) ]
208+ mod tests {
209+ use super :: ToDuckSQL ;
210+ use crate :: { Error , Expr } ;
211+
212+ #[ test]
213+ fn unreachable_code ( ) {
214+ // https://github.com/stac-utils/rustac-py/issues/135
215+ let expr: Expr = serde_json:: from_value ( serde_json:: json!( {
216+ "op" : "and" ,
217+ "args" : [
218+ {
219+ "op" : "eq" ,
220+ "args" : [ { "property" : "forecast:horizon" } , "PT48H" ]
221+ } ,
222+ {
223+ "op" : "gte" ,
224+ "args" : [ { "property" : "forecast:reference_time" } , "2025-05-15T00:00:00Z" ]
225+ } ,
226+ ] ,
227+ } ) )
228+ . unwrap ( ) ;
229+ assert ! ( matches!(
230+ expr. to_ducksql( ) . unwrap_err( ) ,
231+ Error :: InvalidOperator ( _)
232+ ) ) ;
233+ }
234+ }
Original file line number Diff line number Diff line change @@ -87,6 +87,10 @@ pub enum Error {
8787 #[ error( "Operator {0} is not implemented for this type." ) ]
8888 OpNotImplemented ( & ' static str ) ,
8989
90+ /// Invalid operator
91+ #[ error( "{0} is not a valid operator." ) ]
92+ InvalidOperator ( String ) ,
93+
9094 /// Expression not reduced to boolean
9195 #[ error( "Could not reduce expression to boolean" ) ]
9296 NonReduced ( ) ,
You can’t perform that action at this time.
0 commit comments