Skip to content

fix: an unreadable template no longer runs a same-named program - #541

Open
connorburgess wants to merge 1 commit into
herdrdev:masterfrom
connorburgess:fix/unreadable-template
Open

connorburgess wants to merge 1 commit into
herdrdev:masterfrom
connorburgess:fix/unreadable-template

Conversation

@connorburgess

Copy link
Copy Markdown

A template file that is there but can't be read as one (no read permission, bytes that aren't UTF-8, a symlink whose target is gone, or a folder named like a template) shows up in hc templates as broken, but hc run <name> "task" took it for "no such template" and tried to start a program called <name>: it failed with a spawn error about the program name, or quietly started an installed program of the same name with the task text as its arguments.

templates::load now reports the existing invalid_template error, naming the file and the read error, when something is at the template's path but reading it fails. When there is nothing at that path to see (no file, no templates folder, a file where the folder should be, a templates folder that can't be searched, or a program name that isn't a valid file name), the name is still just a program and runs as before. hc templates now shows such an entry's read error after its path instead of a bare "unreadable", the same way it already shows parse errors.

The new unit test templates::tests::only_a_missing_template_file_is_no_template covers a missing file, a file with invalid UTF-8, a folder named folder.md, and a templates folder that isn't there; it fails on master 0b968a2 and passes on the branch. A dangling symlink takes the same path but is not in the test, which stays portable.

Checks on the final head, rebased on master 0b968a2 (macOS): cargo build --locked -p herdr-core finishes. cargo test --locked -p herdr-core --lib templates:: gives 3 passed; with master's load and the new test it gives 2 passed, 1 failed (panicked at crates/herdr-core/src/templates.rs:240:42).

just lint passes: cargo fmt --all -- --check, cargo deny check ("advisories ok, bans ok, licenses ok, sources ok"), cargo clippy --locked --all-targets -- -D warnings, and the Windows clippy (run with AR_x86_64_pc_windows_msvc pointed at a Homebrew llvm-ar, since this Mac has no llvm-ar on PATH). just docs-check passes (cli_docs: 2 passed).

cargo test --locked --no-fail-fast runs to the end with 725 passed, 5 failed, 4 ignored. The five failures are outside templates and fail the same way on unmodified master 0b968a2 on this Mac: distribution's a_machine_of_another_cpu_gets_the_released_build_for_it and machines' interactive_add_uses_the_same_ssh_target_for_login_and_install (both time out in the wait at tests/common/mod.rs:343), and home's membership::join_supports_code_arg_ssh_target_and_tty_enter_prompt, transport::relay_off_unreachable_message_and_instant_inbound_shared_connection and transport::a_same_instance_can_replace_its_stream_and_then_its_connection.

Checked on macOS only. Not checked: Linux, Windows.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant