-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/improve exec error message #71
base: main
Are you sure you want to change the base?
Conversation
app-agent/src/exec_process.rs
Outdated
Err(e) => match e.kind() { | ||
std::io::ErrorKind::NotFound => { | ||
let directory_entries_iter = fs::read_dir("./").unwrap(); | ||
let mut entry_list = String::from("Available files in the current directory:\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's up to the agent to replace ls
.
How about just doing these two things:
If ErrorKind::NotFound
- check if a file with the same name exists in the current directory
- print:
command 'XYZ' not found
Hint: A file named 'XYZ' exists in the current directory. Prepend ./ to execute it.
Example: CMD exec './XYZ'
where CMD
is the alumet binary (in the rapl plugin you can find an example of how to get the path to the current alumet binary on the user).
Bonus
If you want to have fun, implement a fuzzy finder to fix the potential typos :)
Example of what it would look like:
> ls
script.sh
> alumet-local-agent exec ./scrit.sh
ERROR: ...
Hint: did you mean './script.sh'?
Other example:
> ls
script.sh
> alumet-local-agent exec ./script
ERROR: ...
Hint: did you mean './script.sh'?
If permission denied
- check if the file exists but does not have the X or R permission
- print:
file 'XYZ' is missing the following permissions: PERM
Hint: try chmod +PERM 'XYZ'
where PERM
is r
, x
or rx
3e8c5f6
to
eeb5269
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When done, it will be a nice improvement to the agent exec
mode!
app-agent/src/exec_process.rs
Outdated
Err(e) => match e.kind() { | ||
std::io::ErrorKind::NotFound => { | ||
let return_error: String = handle_not_found(external_command, args); | ||
panic!("{}", return_error); | ||
} | ||
std::io::ErrorKind::PermissionDenied => { | ||
let return_error: String = handle_permission_denied(external_command); | ||
panic!("{}", return_error); | ||
} | ||
_ => { | ||
panic!("Error in child process"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function returns a Result
, you should use that instead of panics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in the main you used expect()
I expected to panic in case of error
app-agent/src/exec_process.rs
Outdated
let file_permission_denied = match File::open(external_command.clone()) { | ||
Ok(file) => file, | ||
Err(err) => { | ||
panic!("Error when try to read the file: {}", err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
english
app-agent/src/exec_process.rs
Outdated
4 => "x", | ||
_ => "", | ||
}; | ||
if user_perm == "rx" || group_perm == "rx" || other_perm == "rx" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is all this doing, exactly? Isn't chmod +rx
a solution that always work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I check which rights are missing, the goal is to suggest only to add missing rights, if read is missing but not execute, i will suggest chmod +r
only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's very generous of your part, but chmod
does the checking, no? If chmod +r
works, chmod +rx
will work too. Something that would really be helpful is, maybe, to check the permissions of the folder: what happens if the user wants to execute /a/b/exec
but /a/b
is not readable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, if +r
is missing, +rx
will work too. I found it was more interesting for people to see that, for example, if only read right is missing, but the execute one is already present... But it's as you want, I can just suggest one chmod: chmod +rx
.
About the parent folder, you're totally right, I will check this right in my next commit. I will only check the parent folder but not the parent of the parents, as it could be veryyyyyy long and not necessary, in my opinion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding to 3788bde I check parent of parent to be sure all folder in the path have at least the 'execute' right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to do that, do it properly: compute the missing permissions and print the message that suggests it in one go, without repeating all the possibilities (lines 148 to 162 should be just 2 lines).
833e56b
to
3788bde
Compare
3788bde
to
69a75cf
Compare
…istance with adjacent transpositions
…ction and use it when file not found in exec mode
…ling on exec mode
69a75cf
to
264ef6f
Compare
app-agent/src/exec_process.rs
Outdated
return Err(anyhow!(return_error)); | ||
} | ||
_ => { | ||
panic!("Error in child process"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exec_child
returns a result, please remove the panics
app-agent/src/exec_process.rs
Outdated
let file_permission_denied = match File::open(external_command.clone()) { | ||
Ok(file) => file, | ||
Err(err) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the Ok
branch is very small, you can turn this into a if let
instead. Also, what does file_permission_denied
represent?
It would be cleaner to make it a separate function.
app-agent/src/exec_process.rs
Outdated
let metadata: Metadata; | ||
loop { | ||
match current_parent.metadata() { | ||
Ok(metadata_parent) => { | ||
metadata = metadata_parent; | ||
break; | ||
} | ||
Err(_) => { | ||
current_parent = match current_parent.parent() { | ||
Some(parent) => parent, | ||
None => { | ||
panic!("Unable to retrieve a parent for your file"); | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be cleaner to make it a separate function
app-agent/src/exec_process.rs
Outdated
let user_perm = match file_metadata.permissions().mode() & 0o500 { | ||
0 => "rx", | ||
1 => "r", | ||
4 => "x", | ||
_ => "", | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A function would be handy for deduplication here.
app-agent/src/exec_process.rs
Outdated
4 => "x", | ||
_ => "", | ||
}; | ||
if user_perm == "rx" || group_perm == "rx" || other_perm == "rx" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to do that, do it properly: compute the missing permissions and print the message that suggests it in one go, without repeating all the possibilities (lines 148 to 162 should be just 2 lines).
app-agent/src/exec_process.rs
Outdated
} else { | ||
log::warn!("Can't determine right issue about the file: {}", external_command); | ||
} | ||
"Issue happened about file's permission".to_string() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which issue? Use proper errors propagation
app-agent/src/exec_process.rs
Outdated
args.iter() | ||
.map(|arg| { | ||
if arg.contains(' ') { | ||
format!("\"{}\"", arg) | ||
} else { | ||
arg.to_string() | ||
} | ||
}) | ||
.collect::<Vec<_>>() | ||
.join(" ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please separate the construction of the list from the log call (same everywhere).
app-agent/src/exec_process.rs
Outdated
} | ||
} | ||
None => { | ||
log::warn!("💡 Hint: No matching file exists in the current directory. Prepend ./ to execute it."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What? If there's no matching file, prepending ./
will never work.
app-agent/src/exec_process.rs
Outdated
log::warn!("💡 Hint: No matching file exists in the current directory. Prepend ./ to execute it."); | ||
} | ||
} | ||
"Issue happened because the file was not found".to_string() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which issue?
app-agent/src/lib.rs
Outdated
@@ -6,6 +6,7 @@ pub mod agent_util; | |||
pub mod config_ops; | |||
pub mod exec_process; | |||
pub mod options; | |||
pub mod utils; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please find a better name than utils
. I suggest word_distance
app-agent/src/utils.rs
Outdated
@@ -0,0 +1,170 @@ | |||
use std::collections::HashMap; | |||
|
|||
// Damerau-Levenshtein distance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use triple slash to document function. Please add more details so that we understand what this is without googling.
Fix #6
This PR add a better message when using the exec mode and if the executable is not found.