@@ -47,6 +47,8 @@ pub use instrumentation::*;
4747mod function_query;
4848pub use function_query:: * ;
4949
50+ use crate :: error:: OrchestrionError ;
51+
5052#[ cfg( feature = "wasm" ) ]
5153pub mod wasm;
5254
@@ -112,6 +114,33 @@ impl InstrumentationVisitor {
112114 !self . instrumentations . is_empty ( )
113115 }
114116
117+ #[ must_use]
118+ pub fn get_failed_injections ( & self ) -> Option < Vec < String > > {
119+ let failed: Vec < String > = self
120+ . instrumentations
121+ . iter ( )
122+ . filter_map ( |instr| {
123+ if instr. has_injected ( ) {
124+ None
125+ } else {
126+ Some ( instr. config . function_query . name ( ) . to_string ( ) )
127+ }
128+ } )
129+ . collect ( ) ;
130+
131+ if failed. is_empty ( ) {
132+ None
133+ } else {
134+ Some ( failed)
135+ }
136+ }
137+
138+ pub fn reset_has_injected ( & mut self ) {
139+ for instr in & mut self . instrumentations {
140+ instr. reset_has_injected ( ) ;
141+ }
142+ }
143+
115144 /// Transform the given JavaScript code.
116145 /// # Errors
117146 /// Returns an error if the transformation fails.
@@ -125,7 +154,7 @@ impl InstrumentationVisitor {
125154 ) ) ) ;
126155
127156 #[ allow( clippy:: redundant_closure_for_method_calls) ]
128- Ok ( try_with_handler (
157+ let result = try_with_handler (
129158 compiler. cm . clone ( ) ,
130159 HandlerOpts {
131160 color : ColorConfig :: Never ,
@@ -165,10 +194,20 @@ impl InstrumentationVisitor {
165194 ..Default :: default ( )
166195 } ,
167196 ) ?;
197+
168198 Ok ( result. code )
169199 } ,
170200 )
171- . map_err ( |e| e. to_pretty_error ( ) ) ?)
201+ . map_err ( |e| e. to_pretty_error ( ) ) ?;
202+
203+ let failed_injections = self . get_failed_injections ( ) ;
204+ self . reset_has_injected ( ) ;
205+
206+ if let Some ( failed) = failed_injections {
207+ Err ( Box :: new ( OrchestrionError :: InjectionMatchFailure ( failed) ) )
208+ } else {
209+ Ok ( result)
210+ }
172211 }
173212}
174213
0 commit comments