use std::io;
#[derive(Debug, thiserror::Error)]
pub enum AtariEnvError {
#[error(
"failed to launch the Python worker `{path}`: {source}. \
Install Python 3 and ensure it is on PATH, or set the ATARI_PYTHON \
environment variable to a valid interpreter."
)]
MissingPython {
path: String,
source: io::Error,
},
#[error(
"the ale-py package is not available in the worker's Python \
environment ({0}). Install it with: pip install ale-py"
)]
MissingAlePy(String),
#[error(
"could not resolve the Atari ROM ({0}). Set ALE_ROM_PATH to a \
directory (or file) containing the ROM, or run \
`AutoROM --accept-license` to download ROMs into ale-py's ROM directory."
)]
MissingRom(String),
#[error("Atari worker protocol error: {0}")]
Protocol(String),
#[error("Atari worker reported an error: {0}")]
Worker(String),
#[error("I/O error communicating with the Atari worker: {0}")]
Io(#[from] io::Error),
}
impl AtariEnvError {
#[must_use]
pub fn from_worker_message(msg: String) -> Self {
let lower = msg.to_lowercase();
if lower.contains("rom") {
AtariEnvError::MissingRom(msg)
} else if lower.contains("ale-py")
|| lower.contains("ale_py")
|| lower.contains("no module named")
{
AtariEnvError::MissingAlePy(msg)
} else {
AtariEnvError::Worker(msg)
}
}
}