From 38238212ec5fbc3737c874f6c8c0037bbedbac42 Mon Sep 17 00:00:00 2001 From: "Victor M. Alvarez" Date: Thu, 23 Nov 2023 11:44:52 +0100 Subject: [PATCH] fix(cli): provide more context about errors while trying to read compile rules file --- yara-x-cli/src/commands/scan.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/yara-x-cli/src/commands/scan.rs b/yara-x-cli/src/commands/scan.rs index d1430dd3c..667912b7c 100644 --- a/yara-x-cli/src/commands/scan.rs +++ b/yara-x-cli/src/commands/scan.rs @@ -119,12 +119,17 @@ pub fn exec_scan(args: &ArgMatches) -> anyhow::Result<()> { ); } - // TODO: implement Rules::deserialize_from reader - let mut file = File::open(rules_path.next().unwrap())?; + let rules_path = rules_path.next().unwrap(); + + let mut file = File::open(rules_path) + .with_context(|| format!("can not open {:?}", &rules_path))?; + let mut data = Vec::new(); - File::read_to_end(&mut file, &mut data)?; + File::read_to_end(&mut file, &mut data) + .with_context(|| format!("can not read {:?}", &rules_path))?; + // TODO: implement Rules::deserialize_from reader let rules = Rules::deserialize(data.as_slice())?; // If the user is defining external variables, make sure that these