@@ -6,9 +6,9 @@ use crate::{
66} ;
77#[ cfg( feature = "plugin" ) ]
88use nu_cli:: read_plugin_file;
9- use nu_cli:: { evaluate_commands, evaluate_file, evaluate_repl} ;
9+ use nu_cli:: { evaluate_commands, evaluate_file, evaluate_repl, report_error } ;
1010use nu_parser:: parse_module_block;
11- use nu_protocol:: { engine:: StateWorkingSet , PipelineData , Span } ;
11+ use nu_protocol:: { engine:: StateWorkingSet , PipelineData , ShellError , Span } ;
1212use nu_utils:: utils:: perf;
1313
1414pub ( crate ) fn run_commands (
@@ -261,23 +261,37 @@ pub(crate) fn run_repl(
261261 // ("help operators", "help operators"),
262262 ] ;
263263
264- working_set. use_decls (
265- prelude
266- . iter ( )
267- . map ( |( name, search_name) | {
268- (
269- name. as_bytes ( ) . to_vec ( ) ,
270- module
271- . decls
272- . get ( & search_name. as_bytes ( ) . to_vec ( ) )
273- . unwrap_or_else ( || {
274- panic ! ( "could not load `{}` from `std`." , search_name)
275- } )
276- . to_owned ( ) ,
277- )
278- } )
279- . collect ( ) ,
280- ) ;
264+ let mut decls = Vec :: new ( ) ;
265+ let mut errs = Vec :: new ( ) ;
266+ for ( name, search_name) in prelude {
267+ if let Some ( id) = module. decls . get ( & search_name. as_bytes ( ) . to_vec ( ) ) {
268+ let decl = ( name. as_bytes ( ) . to_vec ( ) , id. to_owned ( ) ) ;
269+ decls. push ( decl) ;
270+ } else {
271+ errs. push ( ShellError :: GenericError (
272+ format ! ( "could not load `{}` from `std`." , search_name) ,
273+ String :: new ( ) ,
274+ None ,
275+ None ,
276+ Vec :: new ( ) ,
277+ ) ) ;
278+ }
279+ }
280+
281+ if !errs. is_empty ( ) {
282+ report_error (
283+ & working_set,
284+ & ShellError :: GenericError (
285+ "Unable to load the prelude of the standard library." . into ( ) ,
286+ String :: new ( ) ,
287+ None ,
288+ Some ( "this is a bug: please file an issue at <issue_tracker_url>" . to_string ( ) ) ,
289+ errs,
290+ ) ,
291+ ) ;
292+ }
293+
294+ working_set. use_decls ( decls) ;
281295
282296 working_set. add_module ( & name, module, comments) ;
283297
0 commit comments