File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -148,9 +148,9 @@ WASI_API_EXTERN void wasi_config_inherit_stdout(wasi_config_t *config);
148148/**
149149 * \brief Configures standard output to be directed to \p callback
150150 *
151- * \param callback The callback that will get called for each write with the
152- * buffer. A positive return value indicates the amount of bytes written.
153- * Negative return values indicate that an error has occured .
151+ * \param callback A non-null callback must be provided, that will get called
152+ * for each write with the buffer. A positive return value indicates the amount
153+ * of bytes written. Negative return values are treated as OS error codes .
154154 * \param data An optional user provided data that will be passed to \p callback
155155 * \param finalizer An optional callback to be called to destroy \p data
156156 */
@@ -180,9 +180,9 @@ WASI_API_EXTERN void wasi_config_inherit_stderr(wasi_config_t *config);
180180/**
181181 * \brief Configures standard error output to be directed to \p callback
182182 *
183- * \param callback The callback that will get called for each write with the
184- * buffer. A positive return value indicates the amount of bytes written.
185- * Negative return values indicate that an error has occured .
183+ * \param callback A non-null callback must be provided, that will get called
184+ * for each write with the buffer. A positive return value indicates the amount
185+ * of bytes written. Negative return values are treated as OS error codes .
186186 * \param data An optional user provided data that will be passed to \p callback
187187 * \param finalizer An optional callback to be called to destroy \p data
188188 */
Original file line number Diff line number Diff line change @@ -202,10 +202,9 @@ impl wasmtime_wasi::p2::OutputStream for CustomOutputStream {
202202 let wrote = self . inner . write ( & bytes) ;
203203
204204 if wrote < 0 {
205- return Err ( StreamError :: Trap ( anyhow:: anyhow!(
206- "Custom write function failed with error code '{}'" ,
207- wrote. abs( )
208- ) ) ) ;
205+ return Err ( StreamError :: Trap (
206+ io:: Error :: from_raw_os_error ( wrote. abs ( ) as _ ) . into ( ) ,
207+ ) ) ;
209208 }
210209
211210 if wrote as usize != bytes. len ( ) {
@@ -234,13 +233,7 @@ impl AsyncWrite for CustomOutputStream {
234233 Poll :: Ready ( if wrote >= 0 {
235234 Ok ( wrote as _ )
236235 } else {
237- Err ( io:: Error :: new (
238- io:: ErrorKind :: Other ,
239- format ! (
240- "Custom write function failed with error code '{}'" ,
241- wrote. abs( )
242- ) ,
243- ) )
236+ Err ( io:: Error :: from_raw_os_error ( wrote. abs ( ) as _ ) )
244237 } )
245238 }
246239 fn poll_flush ( self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
You can’t perform that action at this time.
0 commit comments