@@ -11,9 +11,8 @@ use wasmtime::{
11
11
use wasmtime_wasi:: ResourceTable ;
12
12
13
13
use crate :: {
14
- plugins_shared:: get_wasi_ctx_builder, v0_1_0:: parser:: bindings:: ParseError ,
15
- wasm_host:: get_wasm_host, PluginGuestInitError , PluginHostInitError , PluginParseMessage ,
16
- PluginType , WasmPlugin ,
14
+ plugins_shared:: get_wasi_ctx_builder, wasm_host:: get_wasm_host, PluginGuestInitError ,
15
+ PluginHostInitError , PluginParseMessage , PluginType , WasmPlugin ,
17
16
} ;
18
17
19
18
use self :: {
@@ -81,8 +80,8 @@ impl PluginParser {
81
80
& mut self ,
82
81
input : & [ u8 ] ,
83
82
timestamp : Option < u64 > ,
84
- ) -> impl IntoIterator < Item = Result < ( usize , Option < p:: ParseYield < PluginParseMessage > > ) , p:: Error > >
85
- + Send {
83
+ ) -> Result < impl Iterator < Item = ( usize , Option < p:: ParseYield < PluginParseMessage > > ) > , p:: Error >
84
+ {
86
85
let call_res =
87
86
futures:: executor:: block_on ( self . plugin_bindings . chipmunk_plugin_parser ( ) . call_parse (
88
87
& mut self . store ,
@@ -91,15 +90,16 @@ impl PluginParser {
91
90
) ) ;
92
91
93
92
let parse_results = match call_res {
94
- Ok ( results) => results,
93
+ Ok ( results) => results? ,
95
94
Err ( call_err) => {
96
- vec ! [ Err ( ParseError :: Unrecoverable ( format!(
95
+ return Err ( p :: Error :: Unrecoverable ( format ! (
97
96
"Call parse on the plugin failed. Error: {call_err}"
98
- ) ) ) ]
97
+ ) ) )
99
98
}
100
99
} ;
101
100
102
- parse_results. into_iter ( ) . map ( guest_to_host_parse_results)
101
+ let res = parse_results. into_iter ( ) . map ( guest_to_host_parse_results) ;
102
+ Ok ( res)
103
103
}
104
104
105
105
#[ inline]
@@ -110,48 +110,48 @@ impl PluginParser {
110
110
timestamp : Option < u64 > ,
111
111
) -> Result < impl Iterator < Item = ( usize , Option < p:: ParseYield < PluginParseMessage > > ) > , p:: Error >
112
112
{
113
- //TODO AAZ: Temporary fix.
114
- // In original implementation we were returning Vec<Result<>>
115
- // Now we should return Result<Vec<>>.
116
-
117
- // Old solution:
118
- // debug_assert!(
119
- // self.store.data_mut().results_queue.is_empty(),
120
- // "Host results most be empty at the start of parse call"
121
- // );
122
- //
123
- // let call_res = futures::executor::block_on(
124
- // self.plugin_bindings
125
- // .chipmunk_plugin_parser()
126
- // .call_parse_with_add(&mut self.store, input, timestamp),
127
- // );
128
- //
129
- // let parse_results = if let Err(call_err) = call_res {
130
- // vec![Err(ParseError::Unrecoverable(format!(
131
- // "Call parse on the plugin failed. Error: {call_err}"
132
- // )))]
133
- // } else {
134
- // std::mem::take(&mut self.store.data_mut().results_queue)
135
- // };
136
- //
137
- //
138
- // parse_results.into_iter().map(guest_to_host_parse_results)
139
-
140
- // Temporary:
141
- Ok ( [ ] . into_iter ( ) )
113
+ debug_assert ! (
114
+ self . store. data_mut( ) . results_queue. is_empty( ) ,
115
+ "Host results most be empty at the start of parse call"
116
+ ) ;
117
+
118
+ let parse_res = futures:: executor:: block_on (
119
+ self . plugin_bindings
120
+ . chipmunk_plugin_parser ( )
121
+ . call_parse_with_add ( & mut self . store , input, timestamp) ,
122
+ )
123
+ . map_err ( |call_err| {
124
+ p:: Error :: Unrecoverable ( format ! (
125
+ "Call parse on the plugin failed. Error: {call_err}"
126
+ ) )
127
+ } ) ?;
128
+
129
+ if let Err ( parse_err) = parse_res {
130
+ //TODO AAZ: Decide what to do if we have already parsed items.
131
+
132
+ if !self . store . data ( ) . results_queue . is_empty ( ) {
133
+ self . store . data_mut ( ) . results_queue . clear ( ) ;
134
+ return Err ( p:: Error :: Unrecoverable ( format ! ( "Plugin return parse error and submitted parsed items on the same call. Plugin Error: {parse_err}" ) ) ) ;
135
+ } else {
136
+ return Err ( parse_err. into ( ) ) ;
137
+ }
138
+ }
139
+
140
+ let parse_results = std:: mem:: take ( & mut self . store . data_mut ( ) . results_queue ) ;
141
+
142
+ let res = parse_results. into_iter ( ) . map ( guest_to_host_parse_results) ;
143
+
144
+ Ok ( res)
142
145
}
143
146
}
144
147
145
148
fn guest_to_host_parse_results (
146
- guest_res : Result < ParseReturn , ParseError > ,
147
- ) -> Result < ( usize , Option < p:: ParseYield < PluginParseMessage > > ) , p:: Error > {
148
- match guest_res {
149
- Ok ( parse_res) => Ok ( (
150
- parse_res. consumed as usize ,
151
- parse_res. value . map ( |v| v. into ( ) ) ,
152
- ) ) ,
153
- Err ( parse_err) => Err ( parse_err. into ( ) ) ,
154
- }
149
+ parse_res : ParseReturn ,
150
+ ) -> ( usize , Option < p:: ParseYield < PluginParseMessage > > ) {
151
+ (
152
+ parse_res. consumed as usize ,
153
+ parse_res. value . map ( |v| v. into ( ) ) ,
154
+ )
155
155
}
156
156
157
157
use parsers as p;
0 commit comments