[Low] fix(cli): fix unreachable branch in resolveInput — directories named *.json/yaml now fall through to 'path'#716
Conversation
…*.json/yaml now fall through to 'path'
resolveInput() had two consecutive branches classifying local paths as
'doc' when their extension matched DOC_EXTS (.json, .yaml, .yml, .toml,
.md, .pdf):
if (ext && DOC_EXTS.has(ext)) { // always returns here ↩
return { kind: 'doc', … };
}
if (exists && statSync(abs).isFile() && ext && DOC_EXTS.has(ext)) { // UNREACHABLE
return { kind: 'doc', … };
}
The second branch was clearly intended to restrict 'doc' classification
to actual files (excluding directories that happen to carry a doc-like
extension), but the identical first predicate makes it dead code. The
consequence: 'sh1pt build --from ./config.yaml' where config.yaml is a
directory (a real pattern in consul-template, vault, dotnet) returns
kind='doc', and downstream callers fail with EISDIR when they try to
read it as a file.
Fix: collapse to one correct check that returns 'doc' only when the path
has a doc extension AND either does not exist yet (legitimate future-
output path) or is a confirmed regular file. A directory named *.yaml
now falls through to the 'path' default.
Greptile SummaryThis PR fixes a dead-code bug in
Confidence Score: 5/5Safe to merge — the change is a minimal, targeted collapse of two branches into one correct predicate with no new logic introduced beyond an isFile() guard that was already present in the dead branch. The fix addresses exactly the scenario described in the PR: a directory named *.yaml was previously classified as 'doc' and would cause EISDIR failures downstream. The new combined predicate correctly handles all three cases — regular file, non-existent path, and directory — with no change to other classification branches or the returned ResolvedInput shape. No files require special attention. packages/cli/src/input.ts is the only changed file and the diff is small and self-contained. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["resolveInput(raw)"] --> B{SSH or Git URL?}
B -- yes --> C["kind: git"]
B -- no --> D{HTTPS Git URL?}
D -- yes --> C
D -- no --> E{HTTPS URL?}
E -- yes --> F["kind: url"]
E -- no --> G["Resolve abs path<br/>ext = extname<br/>exists = existsSync"]
G --> H["isDocLike = ext in DOC_EXTS"]
H --> I["isFileOrMissing = !exists OR statSync.isFile()"]
I --> J{"isDocLike AND isFileOrMissing?"}
J -- yes --> K["kind: doc"]
J -- no --> L["kind: path (default)<br/>directories named *.yaml land here"]
Reviews (1): Last reviewed commit: "fix(cli): fix unreachable branch in reso..." | Re-trigger Greptile |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
8 similar comments
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
resolveInput() had two consecutive branches classifying local paths as 'doc' when their extension matched DOC_EXTS (.json, .yaml, .yml, .toml, .md, .pdf):
The second branch was clearly intended to restrict 'doc' classification to actual files (excluding directories that happen to carry a doc-like extension), but the identical first predicate makes it dead code. The consequence:
sh1pt build --from ./config.yamlwhere config.yaml is a directory (a real pattern in consul-template, vault, dotnet) returns kind='doc', and downstream callers fail with EISDIR when they try to read it as a file.Fix: collapse to one correct check that returns 'doc' only when the path has a doc extension AND either does not exist yet (legitimate future-output path) or is a confirmed regular file. A directory named *.yaml now falls through to the 'path' default.
Severity: Low