fix: fix install script informational echo's - #1162
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new info()/error() helpers use echo, which is not fully portable in POSIX /bin/sh for option-like leading arguments (e.g., --prefix), so switching to printf would avoid inconsistent behavior across shells.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR refactors dstack/scripts/install.sh output so resolve_source() can safely return a checkout path on stdout without being interleaved with informational/status messages.
Changes:
- Introduces
info()(stderr) anderror()(stderr witherror:prefix) helper functions. - Replaces direct
echo "error: ..."sites witherror ..., and routesresolve_source()progress messages throughinfo ....
File summaries
| File | Description |
|---|---|
| dstack/scripts/install.sh | Adds info/error helpers and uses them to keep resolve_source() stdout clean for its return value. |
Review details
Suppressed comments (1)
dstack/scripts/install.sh:66
- Same portability concern as
info():echohas implementation-defined behavior for leading-arguments. Useprintfhere too so option-like messages (e.g.,--repo ...) are never misinterpreted.
error() {
echo "error: $*" >&2
}
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Pushed a follow-up commit to this branch ( The stdout leak isn't only from the script's own
|
| Test | base (pre-PR) | this PR before | after |
|---|---|---|---|
temp clone (curl | sh) |
FAIL | FAIL | PASS |
--src fresh clone |
FAIL | FAIL | PASS |
--src update (git pull) |
FAIL | FAIL | PASS |
--src --ref <tag> |
FAIL | PASS | PASS |
| cwd is a checkout | PASS | PASS | PASS |
script_checkout via $0 |
PASS | PASS | PASS |
Plus a full end-to-end run with a stubbed cargo (clone → build → install_bin → summary): exits 0, binary installed, stdout carries only the final summary, all progress on stderr. prek run --from-ref <base> --to-ref HEAD passes, shellcheck included.
resolve_source() returns the checkout path on stdout, so anything else
written there ends up in $checkout. Routing the script's own progress
messages to stderr is not enough: git writes to stdout too. 'git checkout
<branch>' prints the branch-tracking line ('Your branch is up to date
with ...') and 'git pull' prints its fast-forward summary, both on
stdout. That leaves $checkout as a multi-line string, so core_dir() no
longer matches and the following 'cd "$core_checkout"' fails - including
on the default 'curl | sh' path, where --ref defaults to the 'next'
branch.
Redirect the git subshells and clones as a whole rather than adding -q
per command, so a git call added later cannot reintroduce the same bug.
Also use printf instead of echo in info()/error(): echo's handling of a
leading '-' is implementation-defined, and dash swallows 'info "-n"'
entirely.
9e1b99d to
fb5310a
Compare
The resolve_source function echo's a return value but also informational messages. I created an
infofunction for the informational messages such that the return value is not muddied. For completeness-sake I also added anerrorfunction.