Skip to content

fix(cli): report NotInitializedError without a stack trace - #1228

Merged
jeff-r2026 merged 2 commits into
Tencent:mainfrom
jay23606:fix/1227-uncaught-not-initialized
Oct 21, 2026
Merged

jeff-r2026 merged 2 commits into
Tencent:mainfrom
jay23606:fix/1227-uncaught-not-initialized

Conversation

@jay23606

Copy link
Copy Markdown
Contributor

Fixes #1227

Change

status, list and push reject with NotInitializedError when teamai is not initialized, and nothing caught it, so users saw an uncaught Node stack trace. src/index.ts now calls program.parseAsync() and catches NotInitializedError once at the top level: it prints the message with log.error and sets exit code 1, the same outcome env list already gives. Any other error is rethrown unchanged.

Added src/__tests__/e2e/not-initialized-exit.test.ts, which runs the built CLI with an empty HOME for status, list and push --dry-run, and asserts exit 1, the message, and no stack trace.

Design choice

Catching once at the top level (as the issue suggests) rather than in each command. The alternative is a per-command catch in status, list and push, as env-commands.ts does. The top-level catch covers any future command that calls requireInit(); the per-command option is more local but has to be repeated.

Before and after

Before (test run on upstream/main 8dc60b0, build from that tree):

FAIL  "status" prints the message and exits 1 without a stack trace
FAIL  "list" prints the message and exits 1 without a stack trace
FAIL  "push --dry-run" prints the message and exits 1 without a stack trace
AssertionError: expected ... not to contain 'NotInitializedError'
    NotInitializedError: teamai is not initialized. Run `teamai init` first.
        at throwMissingOrInvalid (...)
Tests 3 failed (3)

After (same test, npx vitest run --config vitest.e2e.config.ts src/__tests__/e2e/not-initialized-exit.test.ts --retry 0):

Test Files 1 passed (1)
Tests 3 passed (3)

Real CLI runs after the fix (empty HOME):

$ node dist/index.js status
✖ teamai is not initialized. Run `teamai init` first.
exit=1

$ node dist/index.js --version
0.22.0
exit=0

Other checks: npx tsc --noEmit exit 0, npm run lint exit 0, src/__tests__/cli-path.test.ts 13/13 passed.

Not verified: the full e2e suite and the provider and agent matrix. Those run in CI.

🤖 Generated with Claude Code

status, list and push reject with NotInitializedError when teamai is not
initialized, and nothing caught it, so users saw a Node stack trace. Catch
it once at the top level and print the message with exit code 1, as
env list already does. Other errors are rethrown unchanged.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Signed-off-by: jay23606 <4602056+jay23606@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

No findings in the specified PR diff.

The PR description documents sufficient testing: three passing built-CLI E2E tests and representative real-CLI runs verifying the error message and exit codes. The full suite and provider × agent matrix are explicitly deferred to CI.

Review was read-only; I did not run, build, or install PR code.

@SaulMoro

Copy link
Copy Markdown
Collaborator

@jay23606 Lint & Test is failing on all Node versions in index-codebase-help.test.ts and the import help test. Mind taking a look?

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Signed-off-by: jay23606 <4602056+jay23606@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

No findings in the specified PR diff.

The PR description documents sufficient testing: three passing built-CLI E2E tests and representative real-CLI runs confirming the error message and exit codes. The full suite and provider × agent matrix are explicitly deferred to CI.

The earlier review reported no findings, so none require resolution.

Review was read-only; I did not run, build, or install PR code.

@jeff-r2026
jeff-r2026 merged commit fa6a361 into Tencent:main Oct 21, 2026
14 checks passed
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.

[bug] status, list and push crash with an uncaught NotInitializedError stack trace when teamai is not initialized

3 participants