tmc_langs_python3/
error.rs1use std::path::PathBuf;
4use thiserror::Error;
5use tmc_langs_framework::TmcError;
6use tmc_langs_util::{FileError, JsonError};
7
8#[derive(Debug, Error)]
9pub enum PythonError {
10 #[error("Failed to canonicalize path {0}")]
11 Canonicalize(PathBuf, #[source] std::io::Error),
12 #[error("Failed to deserialize file at {0} to JSON")]
13 Deserialize(PathBuf, #[source] JsonError),
14 #[error("Unexpected output when trying to print Python version: {0}")]
15 VersionPrintError(String),
16 #[error("Failed to parse Python version from {0}")]
17 VersionParseError(String, #[source] std::num::ParseIntError),
18 #[error(
19 "Python version found is too old: minimum major version required is {minimum_required}, but found {found}"
20 )]
21 OldPythonVersion {
22 found: String,
23 minimum_required: String,
24 },
25 #[error("Failed to decode the test runner's HMAC as hex")]
26 UnexpectedHmac,
27 #[error("Failed to verify the test results")]
28 InvalidHmac,
29 #[error(
30 "Failed to locate test results at {path}
31 stdout: {stdout}
32 stderr: {stderr}"
33 )]
34 MissingTestResults {
35 path: PathBuf,
36 stdout: String,
37 stderr: String,
38 },
39
40 #[error("File IO error")]
41 FileError(#[from] FileError),
42 #[error("Error")]
43 Tmc(#[from] tmc_langs_framework::TmcError),
44}
45
46impl From<PythonError> for TmcError {
48 fn from(err: PythonError) -> TmcError {
49 TmcError::Plugin(Box::new(err))
50 }
51}
52
53impl<T> From<PythonError> for Result<T, TmcError> {
55 fn from(from: PythonError) -> Self {
56 Err(TmcError::Plugin(Box::new(from)))
57 }
58}