@@ -188,7 +188,7 @@ fn real_main(cli: &Cli) -> Result<ExitCode, Error> {
188
188
let ( path, code) = if cli. from_file {
189
189
( filter. into ( ) , std:: fs:: read_to_string ( filter) ?)
190
190
} else {
191
- ( "<inline>" . into ( ) , filter. clone ( ) . into_string ( ) . unwrap ( ) )
191
+ ( "<inline>" . into ( ) , filter. clone ( ) . into_string ( ) ? )
192
192
} ;
193
193
194
194
parse ( & path, & code, & vars, & cli. library_path ) . map_err ( Error :: Report ) ?
@@ -248,7 +248,7 @@ where
248
248
{
249
249
for arg_val in args. chunks ( 2 ) {
250
250
if let [ arg, val] = arg_val {
251
- var_val. push ( ( arg. to_str ( ) . unwrap ( ) . to_owned ( ) , f ( val) ?) ) ;
251
+ var_val. push ( ( arg. to_os_string ( ) . into_string ( ) ? , f ( val) ?) ) ;
252
252
}
253
253
}
254
254
Ok ( ( ) )
@@ -258,7 +258,7 @@ fn binds(cli: &Cli) -> Result<Vec<(String, Val)>, Error> {
258
258
let mut var_val = Vec :: new ( ) ;
259
259
260
260
bind ( & mut var_val, & cli. arg , |v| {
261
- Ok ( Val :: Str ( v. to_str ( ) . unwrap ( ) . to_owned ( ) . into ( ) ) )
261
+ Ok ( Val :: Str ( v. to_os_string ( ) . into_string ( ) ? . into ( ) ) )
262
262
} ) ?;
263
263
bind ( & mut var_val, & cli. rawfile , |path| {
264
264
let s = std:: fs:: read_to_string ( path) . map_err ( |e| Error :: Io ( Some ( format ! ( "{path:?}" ) ) , e) ) ;
@@ -269,8 +269,9 @@ fn binds(cli: &Cli) -> Result<Vec<(String, Val)>, Error> {
269
269
} ) ?;
270
270
271
271
let positional = if cli. args { & * cli. posargs } else { & [ ] } ;
272
- let positional = positional. iter ( ) . cloned ( ) . map ( |s| s. into_string ( ) . unwrap ( ) ) ;
273
- let positional: Vec < _ > = positional. map ( Val :: from) . collect ( ) ;
272
+ let positional = positional. iter ( ) . cloned ( ) ;
273
+ let positional = positional. map ( |s| Ok ( Val :: from ( s. into_string ( ) ?) ) ) ;
274
+ let positional = positional. collect :: < Result < Vec < _ > , Error > > ( ) ?;
274
275
275
276
var_val. push ( ( "ARGS" . to_string ( ) , args ( & positional, & var_val) ) ) ;
276
277
let env = std:: env:: vars ( ) . map ( |( k, v) | ( k. into ( ) , Val :: from ( v) ) ) ;
@@ -437,6 +438,7 @@ type FileReports = (load::File<String, PathBuf>, Vec<Report>);
437
438
enum Error {
438
439
Io ( Option < String > , io:: Error ) ,
439
440
Report ( Vec < FileReports > ) ,
441
+ Utf8 ( OsString ) ,
440
442
Parse ( String ) ,
441
443
Jaq ( jaq_core:: Error < Val > ) ,
442
444
Persist ( tempfile:: PersistError ) ,
@@ -473,6 +475,10 @@ impl Termination for Error {
473
475
3
474
476
}
475
477
Self :: NoOutput => 4 ,
478
+ Self :: Utf8 ( s) => {
479
+ eprintln ! ( "Error: failed to interpret as UTF-8: {s:?}" ) ;
480
+ 5
481
+ }
476
482
Self :: Parse ( e) => {
477
483
eprintln ! ( "Error: failed to parse: {e}" ) ;
478
484
5
@@ -492,6 +498,13 @@ impl From<io::Error> for Error {
492
498
}
493
499
}
494
500
501
+ /// Conversion of errors from [`OsString::into_string`].
502
+ impl From < OsString > for Error {
503
+ fn from ( e : OsString ) -> Self {
504
+ Self :: Utf8 ( e)
505
+ }
506
+ }
507
+
495
508
/// Run a filter with given input values and run `f` for every value output.
496
509
///
497
510
/// This function cannot return an `Iterator` because it creates an `RcIter`.
0 commit comments