From 86a1dfae00cba20d0334660c87b0647f0566b089 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 3 Oct 2024 21:46:17 -0700 Subject: [PATCH] use anyhow instead of unwrap --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/main.rs | 15 +++++++-------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e7eb65..29a691b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -51,6 +51,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + [[package]] name = "arrayref" version = "0.3.9" @@ -441,6 +447,7 @@ dependencies = [ name = "roblox_emulator_cli" version = "0.1.1" dependencies = [ + "anyhow", "clap", "roblox_emulator", ] diff --git a/Cargo.toml b/Cargo.toml index 2fb3707..4959320 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,5 +8,6 @@ description = "Use roblox_emulator from cli." authors = ["Rhys Lloyd "] [dependencies] +anyhow = "1.0.89" clap = { version = "4.5.18", features = ["derive"] } roblox_emulator = { version = "0.3.1", registry = "strafesnet" } diff --git a/src/main.rs b/src/main.rs index 0fc9fc9..07e2993 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,23 +21,22 @@ struct RunScriptSubcommand{ input_file:PathBuf, } -fn main(){ +fn main()->anyhow::Result<()>{ let cli=Cli::parse(); match cli.command{ Commands::RunScript(command)=>run_script(command.input_file), } } -fn run_script( - input_file:PathBuf, -){//->Result<(),roblox_emulator::runner::Error>{ +fn run_script(input_file:PathBuf)->anyhow::Result<()>{ let source={ let mut source=String::new(); - std::fs::File::open(input_file).unwrap().read_to_string(&mut source).unwrap(); + std::fs::File::open(input_file)?.read_to_string(&mut source)?; source }; let (mut context,script,services)=roblox_emulator::context::Context::script_singleton(source); - let runner=roblox_emulator::runner::Runner::new().unwrap(); - let runnable=runner.runnable_context(&mut context,&services).unwrap(); - runnable.run_script(script).unwrap(); + let runner=roblox_emulator::runner::Runner::new()?; + let runnable=runner.runnable_context(&mut context,&services)?; + runnable.run_script(script)?; + Ok(()) }