diff --git a/CHANGELOG.md b/CHANGELOG.md index f12ea42..b0c8115 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## CHANGELOG +### v0.8.0 (2021-03-08) + +* Runtime - \[Breaking Change\] Make script errors chainable. + ### v0.7.4 (2021-03-05) * Fix flow control commands scope handling of call info stack diff --git a/Cargo.lock b/Cargo.lock index b99fad2..7476dd3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -118,14 +118,14 @@ dependencies = [ [[package]] name = "duckscript" -version = "0.6.0" +version = "0.7.0" dependencies = [ "fsio", ] [[package]] name = "duckscript_cli" -version = "0.7.4" +version = "0.8.0" dependencies = [ "duckscript", "duckscriptsdk", @@ -133,7 +133,7 @@ dependencies = [ [[package]] name = "duckscriptsdk" -version = "0.7.4" +version = "0.8.0" dependencies = [ "attohttpc", "base64", @@ -147,7 +147,7 @@ dependencies = [ "java-properties", "meval", "num_cpus", - "rand 0.8.3", + "rand", "semver", "serde_json", "uname", @@ -271,11 +271,11 @@ checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" [[package]] name = "fsio" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1fd087255f739f4f1aeea69f11b72f8080e9c2e7645cd06955dad4a178a49e3" +checksum = "a50045aa8931ae01afbc5d72439e8f57f326becb8c70d07dfc816778eff3d167" dependencies = [ - "rand 0.7.3", + "rand", "users", ] @@ -290,17 +290,6 @@ dependencies = [ "regex 0.1.80", ] -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.2.2" @@ -309,7 +298,7 @@ checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ "cfg-if", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -408,9 +397,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "265d751d31d6780a3f956bb5b8022feba2d94eeee5a84ba64f4212eedca42213" +checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a" [[package]] name = "log" @@ -621,19 +610,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom 0.1.16", - "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc 0.2.0", -] - [[package]] name = "rand" version = "0.8.3" @@ -641,19 +617,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" dependencies = [ "libc", - "rand_chacha 0.3.0", - "rand_core 0.6.2", - "rand_hc 0.3.0", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", + "rand_chacha", + "rand_core", + "rand_hc", ] [[package]] @@ -663,16 +629,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" dependencies = [ "ppv-lite86", - "rand_core 0.6.2", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom 0.1.16", + "rand_core", ] [[package]] @@ -681,16 +638,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" dependencies = [ - "getrandom 0.2.2", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", + "getrandom", ] [[package]] @@ -699,7 +647,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" dependencies = [ - "rand_core 0.6.2", + "rand_core", ] [[package]] @@ -784,9 +732,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.1.1" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfd318104249865096c8da1dfabf09ddbb6d0330ea176812a62ec75e40c4166" +checksum = "d493c5f39e02dfb062cd8f33301f90f9b13b650e8c1b1d0fd75c19dd64bff69d" dependencies = [ "bitflags", "core-foundation", @@ -825,9 +773,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.123" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" +checksum = "bd761ff957cb2a45fbb9ab3da6512de9de55872866160b23c25f1a841e99d29f" [[package]] name = "serde_json" @@ -842,9 +790,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.61" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed22b90a0e734a23a7610f4283ac9e5acfb96cbb30dfefa540d66f866f1c09c5" +checksum = "123a78a3596b24fee53a6464ce52d8ecbf62241e6294c7e7fe12086cd161f512" dependencies = [ "proc-macro2", "quote", @@ -859,7 +807,7 @@ checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ "cfg-if", "libc", - "rand 0.8.3", + "rand", "redox_syscall", "remove_dir_all", "winapi 0.3.9", @@ -991,9 +939,9 @@ dependencies = [ [[package]] name = "users" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa4227e95324a443c9fcb06e03d4d85e91aabe9a5a02aa818688b6918b6af486" +checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032" dependencies = [ "libc", "log", @@ -1022,12 +970,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" @@ -1120,9 +1062,9 @@ dependencies = [ [[package]] name = "wildmatch" -version = "1.0.13" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2399814fda0d6999a6bfe9b5c7660d836334deb162a09db8b73d5b38fd8c40a" +checksum = "7f44b95f62d34113cf558c93511ac93027e03e9c29a60dd0fd70e6e025c7270a" [[package]] name = "winapi" diff --git a/duckscript/Cargo.toml b/duckscript/Cargo.toml index 1bc0749..af07b58 100644 --- a/duckscript/Cargo.toml +++ b/duckscript/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "duckscript" -version = "0.6.0" +version = "0.7.0" authors = ["Sagie Gur-Ari "] description = "Simple, extendable and embeddable scripting language." license = "Apache-2.0" @@ -23,7 +23,7 @@ include = [ ] [dependencies] -fsio = "^0.1" +fsio = "^0.2" [badges.codecov] branch = "master" diff --git a/duckscript/src/parser.rs b/duckscript/src/parser.rs index b16c82b..ecd6966 100644 --- a/duckscript/src/parser.rs +++ b/duckscript/src/parser.rs @@ -8,7 +8,7 @@ mod parser_test; use crate::preprocessor; -use crate::types::error::{ErrorInfo, ScriptError}; +use crate::types::error::ScriptError; use crate::types::instruction::{ Instruction, InstructionMetaInfo, InstructionType, PreProcessInstruction, ScriptInstruction, }; @@ -25,9 +25,7 @@ pub fn parse_file(file: &str) -> Result, ScriptError> { match read_text_file(file) { Ok(text) => parse_lines(&text, meta_info), - Err(error) => Err(ScriptError { - info: ErrorInfo::ErrorReadingFile(file.to_string(), Some(error)), - }), + Err(error) => Err(ScriptError::ErrorReadingFile(file.to_string(), Some(error))), } } @@ -92,9 +90,7 @@ fn parse_pre_process_line( start_index: usize, ) -> Result { if line_text.is_empty() { - Err(ScriptError { - info: ErrorInfo::PreProcessNoCommandFound(meta_info), - }) + Err(ScriptError::PreProcessNoCommandFound(meta_info)) } else { let mut command = String::new(); let mut index = start_index; @@ -113,9 +109,7 @@ fn parse_pre_process_line( } if command.is_empty() { - Err(ScriptError { - info: ErrorInfo::PreProcessNoCommandFound(meta_info), - }) + Err(ScriptError::PreProcessNoCommandFound(meta_info)) } else { match parse_arguments(&meta_info, &line_text, index) { Ok(arguments) => { @@ -289,9 +283,7 @@ fn parse_next_value( in_control = false; found_variable_prefix = false; } else { - return Err(ScriptError { - info: ErrorInfo::ControlWithoutValidValue(meta_info.clone()), - }); + return Err(ScriptError::ControlWithoutValidValue(meta_info.clone())); } } else if character == '\\' || character == '"' { argument.push(character); @@ -308,9 +300,7 @@ fn parse_next_value( } else if character == '$' { found_variable_prefix = true; } else { - return Err(ScriptError { - info: ErrorInfo::ControlWithoutValidValue(meta_info.clone()), - }); + return Err(ScriptError::ControlWithoutValidValue(meta_info.clone())); } } else if character == '\\' { if control_as_char { @@ -319,9 +309,7 @@ fn parse_next_value( in_control = true; found_variable_prefix = false; } else { - return Err(ScriptError { - info: ErrorInfo::InvalidControlLocation(meta_info.clone()), - }); + return Err(ScriptError::InvalidControlLocation(meta_info.clone())); } } else if using_quotes && character == '"' { found_end = true; @@ -351,9 +339,7 @@ fn parse_next_value( if allow_quotes { using_quotes = true; } else { - return Err(ScriptError { - info: ErrorInfo::InvalidQuotesLocation(meta_info.clone()), - }); + return Err(ScriptError::InvalidQuotesLocation(meta_info.clone())); } } else if character == '\\' { if control_as_char { @@ -361,9 +347,7 @@ fn parse_next_value( } else if allow_control { in_control = true; } else { - return Err(ScriptError { - info: ErrorInfo::InvalidControlLocation(meta_info.clone()), - }); + return Err(ScriptError::InvalidControlLocation(meta_info.clone())); } } else { argument.push(character); @@ -373,13 +357,9 @@ fn parse_next_value( if in_argument && !found_end && (in_control || using_quotes) { if in_control { - Err(ScriptError { - info: ErrorInfo::ControlWithoutValidValue(meta_info.clone()), - }) + Err(ScriptError::ControlWithoutValidValue(meta_info.clone())) } else { - Err(ScriptError { - info: ErrorInfo::MissingEndQuotes(meta_info.clone()), - }) + Err(ScriptError::MissingEndQuotes(meta_info.clone())) } } else if argument.is_empty() { if using_quotes { @@ -418,9 +398,7 @@ fn find_label( match value { Some(label_value) => { if label_value.is_empty() { - return Err(ScriptError { - info: ErrorInfo::EmptyLabel(meta_info.clone()), - }); + return Err(ScriptError::EmptyLabel(meta_info.clone())); } let mut text = String::new(); diff --git a/duckscript/src/preprocessor/mod.rs b/duckscript/src/preprocessor/mod.rs index 6021e6b..a0d6f80 100644 --- a/duckscript/src/preprocessor/mod.rs +++ b/duckscript/src/preprocessor/mod.rs @@ -11,7 +11,7 @@ mod mod_test; mod include_files_preprocessor; mod print_preprocessor; -use crate::types::error::{ErrorInfo, ScriptError}; +use crate::types::error::ScriptError; use crate::types::instruction::{Instruction, InstructionType}; pub(crate) fn run(instruction: &Instruction) -> Result, ScriptError> { @@ -26,13 +26,13 @@ pub(crate) fn run(instruction: &Instruction) -> Result, ScriptE &instruction_type.arguments, &instruction.meta_info, ), - _ => Err(ScriptError { - info: ErrorInfo::UnknownPreProcessorCommand(instruction.meta_info.clone()), - }), + _ => Err(ScriptError::UnknownPreProcessorCommand( + instruction.meta_info.clone(), + )), }, - None => Err(ScriptError { - info: ErrorInfo::PreProcessNoCommandFound(instruction.meta_info.clone()), - }), + None => Err(ScriptError::PreProcessNoCommandFound( + instruction.meta_info.clone(), + )), }, _ => Ok(vec![]), } diff --git a/duckscript/src/runner.rs b/duckscript/src/runner.rs index f800f91..e64247c 100644 --- a/duckscript/src/runner.rs +++ b/duckscript/src/runner.rs @@ -10,7 +10,7 @@ mod runner_test; use crate::expansion::{self, ExpandedValue}; use crate::parser; use crate::types::command::{CommandResult, Commands, GoToValue}; -use crate::types::error::{ErrorInfo, ScriptError}; +use crate::types::error::ScriptError; use crate::types::instruction::{ Instruction, InstructionMetaInfo, InstructionType, ScriptInstruction, }; @@ -74,9 +74,10 @@ pub fn repl(mut context: Context) -> Result { } } Err(error) => { - return Err(ScriptError { - info: ErrorInfo::Runtime(error.to_string(), Some(InstructionMetaInfo::new())), - }); + return Err(ScriptError::Runtime( + error.to_string(), + Some(InstructionMetaInfo::new()), + )); } }; } @@ -165,12 +166,10 @@ fn run_instructions( if let Some(exit_code_str) = output { if let Ok(exit_code) = exit_code_str.parse::() { if exit_code != 0 { - return Err(ScriptError { - info: ErrorInfo::Runtime( - format!("Exit with error code: {}", exit_code).to_string(), - Some(meta_info.clone()), - ), - }); + return Err(ScriptError::Runtime( + format!("Exit with error code: {}", exit_code).to_string(), + Some(meta_info.clone()), + )); } } } @@ -195,9 +194,7 @@ fn run_instructions( meta_info.clone(), ) { Err(error) => { - return Err(ScriptError { - info: ErrorInfo::Runtime(error, Some(meta_info.clone())), - }); + return Err(ScriptError::Runtime(error, Some(meta_info.clone()))); } _ => (), }; @@ -207,9 +204,7 @@ fn run_instructions( () } CommandResult::Crash(error) => { - let script_error = ScriptError { - info: ErrorInfo::Runtime(error, Some(meta_info)), - }; + let script_error = ScriptError::Runtime(error, Some(meta_info)); if repl_mode { return Ok((runtime.context, EndReason::Crash(script_error))); @@ -231,12 +226,10 @@ fn run_instructions( GoToValue::Label(label) => match runtime.label_to_line.get(&label) { Some(value) => line = *value, None => { - return Err(ScriptError { - info: ErrorInfo::Runtime( - format!("Label: {} not found.", label), - Some(meta_info), - ), - }); + return Err(ScriptError::Runtime( + format!("Label: {} not found.", label), + Some(meta_info), + )); } }, GoToValue::Line(line_number) => line = line_number, diff --git a/duckscript/src/types/command.rs b/duckscript/src/types/command.rs index 0d235af..84d6e8b 100644 --- a/duckscript/src/types/command.rs +++ b/duckscript/src/types/command.rs @@ -7,7 +7,7 @@ #[path = "./command_test.rs"] mod command_test; -use crate::types::error::{ErrorInfo, ScriptError}; +use crate::types::error::ScriptError; use crate::types::instruction::Instruction; use crate::types::runtime::StateValue; use std::collections::HashMap; @@ -123,19 +123,18 @@ impl Commands { let aliases = command.aliases(); if self.commands.contains_key(&name) { - return Err(ScriptError { - info: ErrorInfo::Initialization(format!("Command: {} already defined.", &name)), - }); + return Err(ScriptError::Initialization(format!( + "Command: {} already defined.", + &name + ))); } for alias in &aliases { if self.aliases.contains_key(alias) { - return Err(ScriptError { - info: ErrorInfo::Initialization(format!( - "Alias: {} for command: {} already defined.", - &alias, &name - )), - }); + return Err(ScriptError::Initialization(format!( + "Alias: {} for command: {} already defined.", + &alias, &name + ))); } } diff --git a/duckscript/src/types/error.rs b/duckscript/src/types/error.rs index eadf2ad..924bc63 100644 --- a/duckscript/src/types/error.rs +++ b/duckscript/src/types/error.rs @@ -5,6 +5,7 @@ use crate::types::instruction::InstructionMetaInfo; use fsio::error::FsIOError; +use std::error::Error; use std::fmt; use std::fmt::Display; @@ -31,7 +32,7 @@ fn format_error_message( #[derive(Debug)] /// Holds the error information -pub enum ErrorInfo { +pub enum ScriptError { /// Error Info Type ErrorReadingFile(String, Option), /// Error Info Type @@ -58,59 +59,74 @@ pub enum ErrorInfo { UnknownPreProcessorCommand(InstructionMetaInfo), } -#[derive(Debug)] -/// Script error struct -pub struct ScriptError { - /// Holds the error information - pub info: ErrorInfo, -} - impl Display for ScriptError { /// Formats the script error using the given formatter. fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { - match self.info { - ErrorInfo::ErrorReadingFile(ref file, ref cause) => { + match self { + Self::ErrorReadingFile(ref file, ref cause) => { writeln!(formatter, "Error reading file: {}", file)?; match cause { Some(cause_err) => cause_err.fmt(formatter), None => Ok(()), } } - ErrorInfo::Initialization(ref message) => write!(formatter, "{}", message), - ErrorInfo::Runtime(ref message, ref meta_info) => { + Self::Initialization(ref message) => write!(formatter, "{}", message), + Self::Runtime(ref message, ref meta_info) => { let empty_meta_data = InstructionMetaInfo::new(); let meta_info_value = meta_info.as_ref().unwrap_or(&empty_meta_data); format_error_message(formatter, &meta_info_value, message) } - ErrorInfo::PreProcessNoCommandFound(ref meta_info) => { + Self::PreProcessNoCommandFound(ref meta_info) => { format_error_message(formatter, &meta_info, "preprocessor is missing a command") } - ErrorInfo::ControlWithoutValidValue(ref meta_info) => format_error_message( + Self::ControlWithoutValidValue(ref meta_info) => format_error_message( formatter, &meta_info, "control character found without a valid value", ), - ErrorInfo::InvalidControlLocation(ref meta_info) => { + Self::InvalidControlLocation(ref meta_info) => { format_error_message(formatter, &meta_info, "invalid control character location") } - ErrorInfo::MissingEndQuotes(ref meta_info) => { + Self::MissingEndQuotes(ref meta_info) => { format_error_message(formatter, &meta_info, "missing end quotes") } - ErrorInfo::MissingOutputVariableName(ref meta_info) => { + Self::MissingOutputVariableName(ref meta_info) => { format_error_message(formatter, &meta_info, "missing variable name") } - ErrorInfo::InvalidEqualsLocation(ref meta_info) => { + Self::InvalidEqualsLocation(ref meta_info) => { format_error_message(formatter, &meta_info, "invalid equals sign location") } - ErrorInfo::InvalidQuotesLocation(ref meta_info) => { + Self::InvalidQuotesLocation(ref meta_info) => { format_error_message(formatter, &meta_info, "invalid quotes location") } - ErrorInfo::EmptyLabel(ref meta_info) => { + Self::EmptyLabel(ref meta_info) => { format_error_message(formatter, &meta_info, "empty lable found") } - ErrorInfo::UnknownPreProcessorCommand(ref meta_info) => { + Self::UnknownPreProcessorCommand(ref meta_info) => { format_error_message(formatter, &meta_info, "unknow preprocessor command") } } } } + +impl Error for ScriptError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + match self { + Self::ErrorReadingFile(_, error) => error.as_ref().map(|fsio_error| { + let std_error: &dyn Error = fsio_error; + std_error + }), + Self::Initialization(_) => None, + Self::Runtime(_, _) => None, + Self::PreProcessNoCommandFound(_) => None, + Self::ControlWithoutValidValue(_) => None, + Self::InvalidControlLocation(_) => None, + Self::MissingEndQuotes(_) => None, + Self::MissingOutputVariableName(_) => None, + Self::InvalidEqualsLocation(_) => None, + Self::InvalidQuotesLocation(_) => None, + Self::EmptyLabel(_) => None, + Self::UnknownPreProcessorCommand(_) => None, + } + } +} diff --git a/duckscript/src/types/error_test.rs b/duckscript/src/types/error_test.rs index 3b2ea9d..82c943e 100644 --- a/duckscript/src/types/error_test.rs +++ b/duckscript/src/types/error_test.rs @@ -2,104 +2,78 @@ use super::*; #[test] fn display_error_reading_file() { - let error = ScriptError { - info: ErrorInfo::ErrorReadingFile("test".to_string(), None), - }; + let error = ScriptError::ErrorReadingFile("test".to_string(), None); println!("{}", error); } #[test] fn display_initialization() { - let error = ScriptError { - info: ErrorInfo::Initialization("test".to_string()), - }; + let error = ScriptError::Initialization("test".to_string()); println!("{}", error); } #[test] fn display_runtime_with_meta_info() { - let error = ScriptError { - info: ErrorInfo::Runtime("test".to_string(), Some(InstructionMetaInfo::new())), - }; + let error = ScriptError::Runtime("test".to_string(), Some(InstructionMetaInfo::new())); println!("{}", error); } #[test] fn display_runtime_without_meta_info() { - let error = ScriptError { - info: ErrorInfo::Runtime("test".to_string(), None), - }; + let error = ScriptError::Runtime("test".to_string(), None); println!("{}", error); } #[test] fn display_pre_process_no_command_found() { - let error = ScriptError { - info: ErrorInfo::PreProcessNoCommandFound(InstructionMetaInfo::new()), - }; + let error = ScriptError::PreProcessNoCommandFound(InstructionMetaInfo::new()); println!("{}", error); } #[test] fn display_control_without_valid_value() { - let error = ScriptError { - info: ErrorInfo::ControlWithoutValidValue(InstructionMetaInfo::new()), - }; + let error = ScriptError::ControlWithoutValidValue(InstructionMetaInfo::new()); println!("{}", error); } #[test] fn display_invalid_control_location() { - let error = ScriptError { - info: ErrorInfo::InvalidControlLocation(InstructionMetaInfo::new()), - }; + let error = ScriptError::InvalidControlLocation(InstructionMetaInfo::new()); println!("{}", error); } #[test] fn display_missing_end_quotes() { - let error = ScriptError { - info: ErrorInfo::MissingEndQuotes(InstructionMetaInfo::new()), - }; + let error = ScriptError::MissingEndQuotes(InstructionMetaInfo::new()); println!("{}", error); } #[test] fn display_missing_output_variable_name() { - let error = ScriptError { - info: ErrorInfo::MissingOutputVariableName(InstructionMetaInfo::new()), - }; + let error = ScriptError::MissingOutputVariableName(InstructionMetaInfo::new()); println!("{}", error); } #[test] fn display_invalid_equals_location() { - let error = ScriptError { - info: ErrorInfo::InvalidEqualsLocation(InstructionMetaInfo::new()), - }; + let error = ScriptError::InvalidEqualsLocation(InstructionMetaInfo::new()); println!("{}", error); } #[test] fn display_invalid_quotes_location() { - let error = ScriptError { - info: ErrorInfo::InvalidQuotesLocation(InstructionMetaInfo::new()), - }; + let error = ScriptError::InvalidQuotesLocation(InstructionMetaInfo::new()); println!("{}", error); } #[test] fn display_empty_label() { - let error = ScriptError { - info: ErrorInfo::EmptyLabel(InstructionMetaInfo::new()), - }; + let error = ScriptError::EmptyLabel(InstructionMetaInfo::new()); println!("{}", error); } #[test] fn display_unknown_pre_processor_command() { - let error = ScriptError { - info: ErrorInfo::UnknownPreProcessorCommand(InstructionMetaInfo::new()), - }; + let error = ScriptError::UnknownPreProcessorCommand(InstructionMetaInfo::new()); println!("{}", error); } diff --git a/duckscript_cli/Cargo.toml b/duckscript_cli/Cargo.toml index 011f297..f68657c 100644 --- a/duckscript_cli/Cargo.toml +++ b/duckscript_cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "duckscript_cli" -version = "0.7.4" +version = "0.8.0" authors = ["Sagie Gur-Ari "] description = "The duckscript command line executable." license = "Apache-2.0" @@ -27,8 +27,8 @@ name = "duck" path = "src/main.rs" [dependencies] -duckscript = { version = "^0.6.0", path = "../duckscript" } -duckscriptsdk = { version = "^0.7.0", path = "../duckscript_sdk" } +duckscript = { version = "^0.7", path = "../duckscript" } +duckscriptsdk = { version = "^0.8", path = "../duckscript_sdk" } [badges.codecov] branch = "master" diff --git a/duckscript_cli/src/linter.rs b/duckscript_cli/src/linter.rs index 0fded20..cb9dcdf 100644 --- a/duckscript_cli/src/linter.rs +++ b/duckscript_cli/src/linter.rs @@ -1,5 +1,5 @@ use duckscript::parser; -use duckscript::types::error::{ErrorInfo, ScriptError}; +use duckscript::types::error::ScriptError; use duckscript::types::instruction::{Instruction, InstructionType, ScriptInstruction}; pub(crate) fn lint_file(file: &str) -> Result<(), ScriptError> { @@ -28,9 +28,10 @@ fn lint_instructions(instructions: Vec) -> Result<(), ScriptError> match result { Err(error) => { - return Err(ScriptError { - info: ErrorInfo::Runtime(error, Some(instruction.meta_info.clone())), - }) + return Err(ScriptError::Runtime( + error, + Some(instruction.meta_info.clone()), + )) } _ => (), } diff --git a/duckscript_sdk/Cargo.toml b/duckscript_sdk/Cargo.toml index b0aaaff..b2ff38a 100644 --- a/duckscript_sdk/Cargo.toml +++ b/duckscript_sdk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "duckscriptsdk" -version = "0.7.4" +version = "0.8.0" authors = ["Sagie Gur-Ari "] description = "The duckscript SDK." license = "Apache-2.0" @@ -26,9 +26,9 @@ include = [ attohttpc = "^0.16" base64 = "^0.13" cfg-if = "^1.0" -duckscript = { version = "^0.6.0", path = "../duckscript" } +duckscript = { version = "^0.7", path = "../duckscript" } fs_extra = "^1" -fsio = { version = "^0.1.3", features = ["temp-path"] } +fsio = { version = "^0.2", features = ["temp-path"] } ftp = "^3" glob = "^0.3" home = "^0.5" diff --git a/duckscript_sdk/src/utils/io.rs b/duckscript_sdk/src/utils/io.rs index 59f071f..3335cea 100644 --- a/duckscript_sdk/src/utils/io.rs +++ b/duckscript_sdk/src/utils/io.rs @@ -1,4 +1,4 @@ -use duckscript::types::error::{ErrorInfo, ScriptError}; +use duckscript::types::error::ScriptError; use fsio; use fsio::file::{append_file, ensure_exists, read_file, write_file}; @@ -9,18 +9,14 @@ mod io_test; pub(crate) fn read_text_file(file: &str) -> Result { match fsio::file::read_text_file(file) { Ok(content) => Ok(content), - Err(error) => Err(ScriptError { - info: ErrorInfo::ErrorReadingFile(file.to_string(), Some(error)), - }), + Err(error) => Err(ScriptError::ErrorReadingFile(file.to_string(), Some(error))), } } pub(crate) fn read_raw_file(file: &str) -> Result, ScriptError> { match read_file(file) { Ok(content) => Ok(content), - Err(error) => Err(ScriptError { - info: ErrorInfo::ErrorReadingFile(file.to_string(), Some(error)), - }), + Err(error) => Err(ScriptError::ErrorReadingFile(file.to_string(), Some(error))), } } @@ -41,9 +37,7 @@ pub(crate) fn write_to_file(file: &str, data: &[u8], append: bool) -> Result<(), match result { Ok(content) => Ok(content), - Err(error) => Err(ScriptError { - info: ErrorInfo::Runtime(error.to_string(), None), - }), + Err(error) => Err(ScriptError::Runtime(error.to_string(), None)), } }