diff --git a/src/cli.rs b/src/cli.rs index c47089d..4854560 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -64,8 +64,6 @@ pub(crate) fn run_cli() { }; handle_cli_error(cli_result); - - } fn handle_cli_error(cli_result: Result<(), CliError>) { diff --git a/src/compiler/native_fn/implementations.rs b/src/compiler/native_fn/implementations.rs index 819c475..938adb9 100644 --- a/src/compiler/native_fn/implementations.rs +++ b/src/compiler/native_fn/implementations.rs @@ -60,9 +60,10 @@ pub(crate) fn create_cmd_native_function() -> NativeFunction { name: String::from("cmd"), }, executor: |arguments: HashMap| { - let arg0 = get_argument_at(&arguments, 0)?; + let command = get_argument_at(&arguments, 0)? + .as_string() + .map_err(|e| NativeFunctionError::Unknown(e.to_string()))?; - let command = arg0.as_string(); let output = std::process::Command::new(command) .output() .map_err(|e| @@ -86,7 +87,8 @@ pub(crate) fn create_read_file_native_function() -> NativeFunction { executor: |arguments: HashMap| { let arg0 = get_argument_at(&arguments, 0)?; - let file_path = arg0.as_string(); + let file_path = arg0.as_string() + .map_err(|e| NativeFunctionError::Unknown(e.to_string()))?; let mut file = File::open(file_path) .map_err(|e| diff --git a/src/compiler/util/byte_buffer.rs b/src/compiler/util/byte_buffer.rs index 083ebf2..5359a2c 100644 --- a/src/compiler/util/byte_buffer.rs +++ b/src/compiler/util/byte_buffer.rs @@ -1,5 +1,6 @@ use crate::compiler::util::encoding::to_shrunk_bytes; use std::fmt::{Debug, Formatter}; +use std::string::FromUtf8Error; #[derive(Clone)] pub(crate) struct ByteBuffer { @@ -67,8 +68,8 @@ impl ByteBuffer { (padded.inner[3] as usize) } - pub(crate) fn as_string(&self) -> String { - String::from_utf8(self.inner.clone()).unwrap() + pub(crate) fn as_string(&self) -> Result { + return String::from_utf8(self.inner.clone()) } }