Skip to content

Fix CLI completion install errors and Homebrew tap detection#1487

Merged
ChiragAgg5k merged 1 commit intomasterfrom
fix/cli-completion-and-homebrew-tap-detection
Apr 28, 2026
Merged

Fix CLI completion install errors and Homebrew tap detection#1487
ChiragAgg5k merged 1 commit intomasterfrom
fix/cli-completion-and-homebrew-tap-detection

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

Addresses two findings from the Greptile review on appwrite/sdk-for-cli#304.

What's Changed

  • P1 — templates/cli/lib/completions.ts: Wrap the completion install action handler in a try/catch. installCompletion calls fs.mkdirSync and fs.writeFileSync synchronously, so an EACCES on ~/.zfunc (or any other filesystem error) used to crash the process with a raw stack trace. We now print Failed to install <shell> completion: <message> to stderr and exit with a non-zero code.
  • P2 — templates/cli/lib/utils.ts: Broaden getInstalledHomebrewFormula so users who installed via a non-official tap (e.g. homebrew/core/appwrite, or a personal tap whose formula tail is appwrite) are detected correctly. Previously the lookup only matched appwrite/appwrite/appwrite and the bare name appwrite; anything else fell through to the official tap formula, and the subsequent brew upgrade appwrite/appwrite/appwrite would fail with "formula not installed". The official tap is still preferred when it's installed; the recommendation hint to switch to the official tap continues to fire as before.

Verification

  • Regenerated examples/cli/ via php example.php cli — both fixes are reflected in the regenerated examples/cli/lib/completions.ts and examples/cli/lib/utils.ts.
  • Templates only — no language class or getFiles() changes required.

Follow-up

After merge, cut a new sdk-generator release and regenerate appwrite/sdk-for-cli so 19.2.0 ships with these fixes.

* Wrap the `completion install` action in a try/catch so filesystem errors
  (e.g. EACCES on `~/.zfunc`) print a friendly message and set a non-zero
  exit code instead of crashing with a raw stack trace.
* Broaden `getInstalledHomebrewFormula` to match any installed formula
  whose tail segment is the executable name. Without this, users who
  installed via a non-official tap (e.g. `homebrew/core/appwrite`) fell
  back to the official tap formula and `brew upgrade` failed with
  "formula not installed".
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 28, 2026

Greptile Summary

This PR applies two targeted fixes to the CLI SDK templates: a try/catch around installCompletion in completions.ts to surface filesystem errors gracefully, and a broadened formula-detection fallback in utils.ts that matches any installed Homebrew formula whose last path segment equals the executable name. Both changes are narrow, well-scoped, and the examples directory has been regenerated to reflect them.

Confidence Score: 5/5

Safe to merge — both changes are narrow bug fixes with no regressions introduced.

No P0 or P1 issues found. The try/catch in completions.ts correctly uses process.exitCode rather than process.exit() so commander can finish cleanly. The tapMatch fallback in utils.ts is sound: preferred formulas are always checked first, empty lines are filtered before the loop, and brew list --formula --full-name output is alphabetically ordered so the fallback result is deterministic.

No files require special attention.

Important Files Changed

Filename Overview
templates/cli/lib/completions.ts Wraps installCompletion in try/catch; writes to stderr and sets process.exitCode = 1 on failure — correct approach that lets commander.js finish before exiting.
templates/cli/lib/utils.ts Adds a fallback tapMatch pass that matches any installed formula whose last /-delimited segment equals the executable name; preferred formulas are still checked first.

Reviews (1): Last reviewed commit: "Fix CLI completion install errors and Ho..." | Re-trigger Greptile

@ChiragAgg5k ChiragAgg5k merged commit f21a556 into master Apr 28, 2026
55 of 56 checks passed
@ChiragAgg5k ChiragAgg5k deleted the fix/cli-completion-and-homebrew-tap-detection branch April 28, 2026 11:12
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