Skip to content

Commit 6092c07

Browse files
committed
better error message for freeze-stdlib
1 parent 09d7433 commit 6092c07

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

vm/src/vm/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,22 +230,26 @@ impl VirtualMachine {
230230
Some(s.as_str()) == rustpythonpath_env.as_deref() || Some(s.as_str()) == pythonpath_env.as_deref()
231231
});
232232

233-
let guide_message = if !env_set {
233+
let guide_message = if cfg!(feature = "freeze-stdlib") {
234+
"`rustpython_pylib` maybe not set while using `freeze-stdlib` feature. Try using `rustpython::InterpreterConfig::init_stdlib` or manually call `vm.add_frozen(rustpython_pylib::FROZEN_STDLIB)` in `rustpython_vm::Interpreter::with_init`."
235+
} else if !env_set {
234236
"Neither RUSTPYTHONPATH nor PYTHONPATH is set. Try setting one of them to the stdlib directory."
235237
} else if path_contains_env {
236238
"RUSTPYTHONPATH or PYTHONPATH is set, but it doesn't contain the encodings library. If you are customizing the RustPython vm/interpreter, try adding the stdlib directory to the path. If you are developing the RustPython interpreter, it might be a bug during development."
237239
} else {
238240
"RUSTPYTHONPATH or PYTHONPATH is set, but it wasn't loaded to `Settings::path_list`. If you are going to customize the RustPython vm/interpreter, those environment variables are not loaded in the Settings struct by default. Please try creating a customized instance of the Settings struct. If you are developing the RustPython interpreter, it might be a bug during development."
239241
};
240242

241-
let msg = format!(
243+
let mut msg = format!(
242244
"RustPython could not import the encodings module. It usually means something went wrong. Please carefully read the following messages and follow the steps.\n\
243245
\n\
244-
{guide_message}\n\
246+
{guide_message}");
247+
if !cfg!(feature = "freeze-stdlib") {
248+
msg += "\n\
245249
If you don't have access to a consistent external environment (e.g. targeting wasm, embedding \
246250
rustpython in another application), try enabling the `freeze-stdlib` feature.\n\
247-
If this is intended and you want to exclude the encodings module from your interpreter, please remove the `encodings` feature from `rustpython-vm` crate."
248-
);
251+
If this is intended and you want to exclude the encodings module from your interpreter, please remove the `encodings` feature from `rustpython-vm` crate.";
252+
}
249253

250254
let err = self.new_runtime_error(msg);
251255
err.set_cause(Some(import_err));

0 commit comments

Comments
 (0)