An open source design system that's fully customizable and agent ready
TypeScript
fix(cli): report ERR_CORE_NOT_FOUND from search when core is missing (#6525)
Joey20b1042e29f6
diff --git a/.changeset/cli-spec-search-core-not-found-code.md b/.changeset/cli-spec-search-core-not-found-code.mdnew file mode 100644index 0000000000..6d5aed652c--- /dev/null+++ b/.changeset/cli-spec-search-core-not-found-code.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[fix] `astryx search` now fails with `ERR_CORE_NOT_FOUND`, like `component` and `hook`, when `@astryxdesign/core` cannot be found, instead of the catch-all `ERR_UNKNOWN`.++@josephfarinadiff --git a/packages/cli/api/search/search.doc.mjs b/packages/cli/api/search/search.doc.mjsindex b6ec498b95..04e53efa66 100644--- a/packages/cli/api/search/search.doc.mjs+++ b/packages/cli/api/search/search.doc.mjs@@ -61,6 +61,10 @@ export const doc = {code: 'ERR_INVALID_ARGUMENT',when: 'the query is empty, --type is unknown, or --limit is not a positive integer',},+ {+ code: 'ERR_CORE_NOT_FOUND',+ when: '@astryxdesign/core cannot be found from the cwd',+ },],examples: [{label: 'Find a component', code: "const r = await search('button');"},diff --git a/packages/cli/api/search/search.mjs b/packages/cli/api/search/search.mjsindex 40237e49a9..1e8da9ba38 100644--- a/packages/cli/api/search/search.mjs+++ b/packages/cli/api/search/search.mjs@@ -921,7 +921,11 @@ export async function search(query, options = {}) {const coreDir = findCoreDir(cwd);if (!coreDir) {- throw new AstryxError('Could not find @astryxdesign/core package');+ throw new AstryxError(+ 'Could not find @astryxdesign/core package',+ undefined,+ ERROR_CODES.ERR_CORE_NOT_FOUND,+ );}// Gather candidates from each requested domain in parallel.diff --git a/packages/cli/api/search/search.test.mjs b/packages/cli/api/search/search.test.mjsindex 6bebf52473..c6a937f12f 100644--- a/packages/cli/api/search/search.test.mjs+++ b/packages/cli/api/search/search.test.mjs@@ -21,6 +21,7 @@import {describe, it, expect} from 'vitest';import * as fs from 'node:fs';+import * as os from 'node:os';import * as path from 'node:path';import {fileURLToPath} from 'node:url';import {@@ -182,6 +183,17 @@ describe('search leaf — error paths (pinned)', () => {search('button', {cwd, type: /** @type {any} */ ('bogus')}),).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});}, SLOW);++ it('throws ERR_CORE_NOT_FOUND when @astryxdesign/core cannot be found', async () => {+ const empty = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-search-no-core-'));+ try {+ await expect(search('button', {cwd: empty})).rejects.toMatchObject({+ code: 'ERR_CORE_NOT_FOUND',+ });+ } finally {+ fs.rmSync(empty, {recursive: true, force: true});+ }+ }, SLOW);});describe('search leaf — limit validation (API matches the CLI contract)', () => {diff --git a/packages/cli/clients/cli/commands/search.doc.mjs b/packages/cli/clients/cli/commands/search.doc.mjsindex d2b0bce435..19d8b3ec37 100644--- a/packages/cli/clients/cli/commands/search.doc.mjs+++ b/packages/cli/clients/cli/commands/search.doc.mjs@@ -45,7 +45,10 @@ export const doc = {],exitCodes: [{code: 0, when: 'success (including zero matches)'},- {code: 1, when: 'invalid --type or a non-positive --limit'},+ {+ code: 1,+ when: 'invalid --type or a non-positive --limit, or @astryxdesign/core cannot be found',+ },],related: ['component', 'hook', 'docs', 'template', 'build'],};diff --git a/packages/cli/clients/cli/commands/search.test.mjs b/packages/cli/clients/cli/commands/search.test.mjsindex f309e6b452..cb1b1f326c 100644--- a/packages/cli/clients/cli/commands/search.test.mjs+++ b/packages/cli/clients/cli/commands/search.test.mjs@@ -11,6 +11,8 @@*/import {describe, it, expect} from 'vitest';+import * as fs from 'node:fs';+import * as os from 'node:os';import * as path from 'node:path';import {fileURLToPath} from 'node:url';import {search, scoreCandidate, SEARCH_DOMAINS} from '../../../api/search/search.mjs';@@ -282,4 +284,17 @@ describe('search CLI — exit codes + JSON contract', () => {expect(r.stdout).toContain('score:');expect(r.stdout).toContain('reason:');});++ it('exits 1 with ERR_CORE_NOT_FOUND when no @astryxdesign/core is reachable', async () => {+ const empty = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-search-cli-no-core-'));+ try {+ const json = await runCli(['--json', 'search', 'button'], empty);+ expect(json.status).toBe(1);+ expect(JSON.parse(json.stdout)).toMatchObject({code: 'ERR_CORE_NOT_FOUND'});+ const text = await runCli(['search', 'button'], empty);+ expect(text.status).toBe(1);+ } finally {+ fs.rmSync(empty, {recursive: true, force: true});+ }+ });}, SCAN_TIMEOUT);