Skip to content

Commit c73a45f

Browse files
committed
Propagate filesystem decoding errors in new file runners
Adapt upstream script filename and sys.path callers to the fallible filesystem decoder after rebase. Assisted-by: OpenAI Codex:model version not exposed
1 parent f80f2c7 commit c73a45f

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

‎crates/vm/src/vm/python_run.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ mod file_run {
106106
/// Execute a Python file with __main__ module setup.
107107
/// Sets __file__ and __cached__ before execution, removes them after.
108108
fn run_simple_file(&self, scope: Scope, path: &Path) -> PyResult<()> {
109-
let filename = self.fsdecode(path.as_os_str());
109+
let filename = self.fsdecode(path.as_os_str())?;
110110
self.with_simple_run(&filename, |module_dict| {
111111
self.run_simple_file_inner(module_dict, scope, path, &filename)
112112
})

‎src/lib.rs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ fn run_file(vm: &VirtualMachine, scope: Scope, argv0: impl AsRef<Path>) -> PyRes
227227
// config_run_filename_abspath: __file__ and co_filename are absolute even
228228
// when the script was named relative to the working directory.
229229
let path = abs_path(argv0);
230-
let filename = vm.fsdecode(path.as_os_str());
230+
let filename = vm.fsdecode(path.as_os_str())?;
231231

232232
// Check if path is a package/directory with __main__.py
233233
if let Some(_importer) = get_importer(&filename, vm)? {
@@ -240,7 +240,10 @@ fn run_file(vm: &VirtualMachine, scope: Scope, argv0: impl AsRef<Path>) -> PyRes
240240

241241
// Add script directory to sys.path[0]
242242
if !vm.state.config.settings.safe_path {
243-
vm.insert_sys_path(vm.fsdecode(script_sys_path0(argv0).into_os_string()).into())?;
243+
vm.insert_sys_path(
244+
vm.fsdecode(script_sys_path0(argv0).into_os_string())?
245+
.into(),
246+
)?;
244247
}
245248

246249
cfg_select! {
@@ -367,7 +370,7 @@ fn pymain_run_python(vm: &VirtualMachine, run_mode: RunMode) -> PyResult<u32> {
367370
};
368371

369372
if let Some(path) = path0 {
370-
vm.insert_sys_path(vm.fsdecode(path.into_os_string()).into())?;
373+
vm.insert_sys_path(vm.fsdecode(path.into_os_string())?.into())?;
371374
}
372375
}
373376

0 commit comments

Comments
 (0)