Skip to content

Commit c3cc15e

Browse files
committed
improved error handling and tests
1 parent d5d212b commit c3cc15e

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

tmc-langs-python3/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub enum PythonError {
1919
FileRemove(PathBuf, std::io::Error),
2020
#[error("Failed to remove directory {0}: {1}")]
2121
DirRemove(PathBuf, std::io::Error),
22+
#[error(transparent)]
23+
Framework(#[from] tmc_langs_framework::Error),
2224
}
2325

2426
impl From<PythonError> for TmcError {

tmc-langs-python3/src/plugin.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,18 @@ fn run_tmc_command(
108108
let (name, mut command) = match &*LOCAL_PY {
109109
LocalPy::Unix => ("python3", Command::new("python3")),
110110
LocalPy::Windows => ("py", Command::new("py")),
111-
//.map_err(|e| PythonError::Command("py", e))?,
112111
LocalPy::WindowsConda { conda_path } => ("conda", Command::new(conda_path)),
113112
};
114113
let command = match &*LOCAL_PY {
115-
LocalPy::Unix => command
116-
.args(&common_args)
117-
.args(extra_args)
118-
.current_dir(path),
119-
LocalPy::Windows => command
120-
.args(&["-3"])
121-
.args(&common_args)
122-
.args(extra_args)
123-
.current_dir(path),
124-
LocalPy::WindowsConda { .. } => command
125-
.args(&common_args)
126-
.args(extra_args)
127-
.current_dir(path),
114+
LocalPy::Unix => &mut command,
115+
LocalPy::Windows => command.args(&["-3"]),
116+
LocalPy::WindowsConda { .. } => &mut command,
128117
};
129-
let output = CommandWithTimeout(command)
130-
.wait_with_timeout(name, timeout)
131-
.unwrap();
118+
let command = command
119+
.args(&common_args)
120+
.args(extra_args)
121+
.current_dir(path);
122+
let output = CommandWithTimeout(command).wait_with_timeout(name, timeout)?;
132123

133124
log::debug!("stdout: {}", String::from_utf8_lossy(&output.stdout));
134125
log::debug!("stderr: {}", String::from_utf8_lossy(&output.stderr));
@@ -194,17 +185,26 @@ mod test {
194185
.collect();
195186
let temp_path = temp.path().join(entry_path);
196187
temp_path.parent().map(|p| std::fs::create_dir_all(&p)); // ignore result, errors on windows
197-
log::trace!("copying {:?} -> {:?}", entry.path(), temp_path);
188+
log::trace!(
189+
"copying {} -> {}",
190+
entry.path().display(),
191+
temp_path.display()
192+
);
198193
std::fs::copy(entry.path(), temp_path).unwrap();
199194
}
200195
}
196+
let _ = fs::remove_file(temp.path().join("tmc")); // delete symlink
201197
for entry in walkdir::WalkDir::new("tests/data/tmc") {
202198
let entry = entry.unwrap();
203199
if entry.path().is_file() {
204200
let entry_path: PathBuf = entry.path().components().skip(2).collect();
205201
let temp_path = temp.path().join(entry_path);
206202
temp_path.parent().map(|p| std::fs::create_dir_all(&p)); // ignore result, errors on windows
207-
log::trace!("copying {:?} -> {:?}", entry.path(), temp_path);
203+
log::trace!(
204+
"copying {} -> {}",
205+
entry.path().display(),
206+
temp_path.display()
207+
);
208208
std::fs::copy(entry.path(), temp_path).unwrap();
209209
}
210210
}

0 commit comments

Comments
 (0)