Add error handling

This commit is contained in:
Jai A
2021-07-09 20:05:04 -07:00
parent a0e35ad853
commit 54cd2f873c
12 changed files with 586 additions and 336 deletions

View File

@@ -1,21 +1,20 @@
use crate::launcher::LauncherError;
use lazy_static::lazy_static;
use regex::Regex;
use std::process::Command;
#[derive(thiserror::Error, Debug)]
pub enum JavaError {
#[error("System Error")]
SystemError(#[from] std::io::Error),
}
lazy_static! {
static ref JAVA_VERSION_REGEX: Regex = Regex::new(r#""(.*?)""#).unwrap();
}
pub fn check_java() -> Result<Option<String>, JavaError> {
let child = Command::new("/usr/lib/jvm/java-8-openjdk/jre/bin/java")
pub fn check_java() -> Result<Option<String>, LauncherError> {
let child = Command::new("java")
.arg("-version")
.output()?;
.output()
.map_err(|err| LauncherError::ProcessError {
inner: err,
process: "java".to_string(),
})?;
let output = &*String::from_utf8_lossy(&*child.stderr);