Repository navigation
fix(task): improve error message when task files are not executable #8705
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
33ae563
fix(task): improve error message when task files are not executable
jdx 6526c3f
refactor(task): simplify non-executable file iterator chain
jdx 2422f4d
[autofix.ci] apply automated fixes
autofix-ci[bot] 2523b69
fix(task): skip hidden files and fix false warning on filtered tasks
jdx a363a40
fix(task): allow hidden root dirs like .mise-tasks in non-exec scan
jdx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Test that non-executable files in mise-tasks/ give a helpful error message | ||
| # Issue: https://github.com/jdx/mise/discussions/8614 | ||
|
|
||
| # Create a mise-tasks directory with non-executable files | ||
| mkdir -p mise-tasks | ||
| cat <<'EOF' >mise-tasks/build | ||
| #!/usr/bin/env bash | ||
| echo "building" | ||
| EOF | ||
| cat <<'EOF' >mise-tasks/test | ||
| #!/usr/bin/env bash | ||
| echo "testing" | ||
| EOF | ||
|
|
||
| # Ensure files are NOT executable | ||
| chmod -x mise-tasks/build mise-tasks/test | ||
|
|
||
| # Create a minimal mise.toml so the directory is recognized as a project | ||
| cat <<EOF >mise.toml | ||
| EOF | ||
|
|
||
| # Running a task should give a helpful error mentioning non-executable files | ||
| assert_fail_contains "mise run build" "non-executable" | ||
| assert_fail_contains "mise run build" "chmod +x" | ||
|
|
||
| # mise tasks ls should warn about non-executable files | ||
| assert_contains "mise tasks 2>&1" "non-executable" | ||
|
|
||
| # After making files executable, tasks should work | ||
| chmod +x mise-tasks/build mise-tasks/test | ||
| assert_contains "mise tasks" "build" | ||
| assert_contains "mise tasks" "test" | ||
| assert "mise run build" "building" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,24 @@ use std::iter::once; | |||||||||||||||||||||||||
| use std::path::PathBuf; | ||||||||||||||||||||||||||
| use std::sync::Arc; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /// Find non-executable files in task include directories. | ||||||||||||||||||||||||||
| /// These are files that likely should be tasks but are missing the executable bit. | ||||||||||||||||||||||||||
| /// Skips hidden files (e.g., .gitkeep, .DS_Store) to match load_tasks_includes behavior. | ||||||||||||||||||||||||||
| pub fn find_non_executable_task_files(includes: &[PathBuf]) -> Vec<PathBuf> { | ||||||||||||||||||||||||||
| includes | ||||||||||||||||||||||||||
| .iter() | ||||||||||||||||||||||||||
| .filter(|d| d.is_dir()) | ||||||||||||||||||||||||||
| .flat_map(|d| { | ||||||||||||||||||||||||||
| walkdir::WalkDir::new(d) | ||||||||||||||||||||||||||
| .into_iter() | ||||||||||||||||||||||||||
| .filter_entry(|e| !e.file_name().to_string_lossy().starts_with('.')) | ||||||||||||||||||||||||||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||||||
| .filter_map(|e| e.ok()) | ||||||||||||||||||||||||||
| .filter(|e| e.file_type().is_file() && !file::is_executable(e.path())) | ||||||||||||||||||||||||||
| .map(|e| e.path().to_path_buf()) | ||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||
| .collect() | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /// Split a task spec into name and args | ||||||||||||||||||||||||||
| /// e.g., "task arg1 arg2" -> ("task", vec!["arg1", "arg2"]) | ||||||||||||||||||||||||||
| pub fn split_task_spec(spec: &str) -> (&str, Vec<String>) { | ||||||||||||||||||||||||||
|
|
@@ -123,6 +141,35 @@ async fn err_no_task(config: &Config, name: &str) -> Result<()> { | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Check if there are non-executable files in task include directories | ||||||||||||||||||||||||||
| if !cfg!(windows) | ||||||||||||||||||||||||||
| && let Some(cwd) = &*dirs::CWD | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| let includes = config::task_includes_for_dir(cwd, &config.config_files); | ||||||||||||||||||||||||||
| let non_exec_files = find_non_executable_task_files(&includes); | ||||||||||||||||||||||||||
| if !non_exec_files.is_empty() { | ||||||||||||||||||||||||||
| let dirs_with_files: Vec<String> = includes | ||||||||||||||||||||||||||
| .iter() | ||||||||||||||||||||||||||
| .filter(|d| d.is_dir()) | ||||||||||||||||||||||||||
| .map(display_path) | ||||||||||||||||||||||||||
| .collect(); | ||||||||||||||||||||||||||
| bail!( | ||||||||||||||||||||||||||
| "no tasks defined in {}, but found {} non-executable file(s) in {}.\n\ | ||||||||||||||||||||||||||
| Files must be executable to be detected as tasks.\n\ | ||||||||||||||||||||||||||
| Run `chmod +x` on the task files to fix this, e.g.:\n chmod +x {}", | ||||||||||||||||||||||||||
| display_path(dirs::CWD.clone().unwrap_or_default()), | ||||||||||||||||||||||||||
| non_exec_files.len(), | ||||||||||||||||||||||||||
| dirs_with_files.join(", "), | ||||||||||||||||||||||||||
| non_exec_files | ||||||||||||||||||||||||||
| .iter() | ||||||||||||||||||||||||||
| .take(5) | ||||||||||||||||||||||||||
| .map(display_path) | ||||||||||||||||||||||||||
| .collect::<Vec<_>>() | ||||||||||||||||||||||||||
| .join(" "), | ||||||||||||||||||||||||||
|
Comment on lines
+167
to
+172
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
File paths are joined with a plain space: if any task file has a space in its name (e.g.
Suggested change
|
||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| bail!( | ||||||||||||||||||||||||||
| "no tasks defined in {}. Are you in a project directory?", | ||||||||||||||||||||||||||
| display_path(dirs::CWD.clone().unwrap_or_default()) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.