|
1 | 1 | import {stat} from 'node:fs/promises' |
2 | 2 |
|
3 | 3 | import {Flags} from '@oclif/core' |
4 | | -import {SanityCommand, subdebug} from '@sanity/cli-core' |
| 4 | +import {SanityCommand} from '@sanity/cli-core' |
5 | 5 | import {chalk, spinner} from '@sanity/cli-core/ux' |
6 | 6 | import {omit, once} from 'lodash-es' |
7 | 7 |
|
8 | 8 | import {runTypegenGenerate} from '../../actions/typegenGenerate.js' |
9 | 9 | import {runTypegenWatcher} from '../../actions/typegenWatch.js' |
10 | 10 | import {configDefinition, readConfig, type TypeGenConfig} from '../../readConfig.js' |
11 | 11 | import {TypegenWatchModeTrace, TypesGeneratedTrace} from '../../typegen.telemetry.js' |
| 12 | +import {debug} from '../../utils/debug.js' |
12 | 13 | import {promiseWithResolvers} from '../../utils/promiseWithResolvers.js' |
13 | 14 | import {telemetry} from '../../utils/telemetryLogger.js' |
14 | 15 |
|
15 | | -const debug = subdebug('typegen:generate') |
16 | | - |
17 | 16 | const description = `Sanity TypeGen (Beta) |
18 | 17 | This command is currently in beta and may undergo significant changes. Feedback is welcome! |
19 | 18 |
|
@@ -89,21 +88,21 @@ export class TypegenGenerateCommand extends SanityCommand<typeof TypegenGenerate |
89 | 88 | // check if the legacy config exist |
90 | 89 | const legacyConfigPath = configPath || 'sanity-typegen.json' |
91 | 90 | let hasLegacyConfig = false |
| 91 | + |
92 | 92 | try { |
93 | 93 | const file = await stat(legacyConfigPath) |
94 | 94 | hasLegacyConfig = file.isFile() |
95 | 95 | } catch (err) { |
96 | 96 | if (err instanceof Error && 'code' in err && err.code === 'ENOENT' && configPath) { |
97 | | - throw new Error(`Typegen config file not found: ${configPath}`, {cause: err}) |
| 97 | + spin.fail() |
| 98 | + this.error(`Typegen config file not found: ${configPath}`, {exit: 1}) |
98 | 99 | } |
99 | 100 |
|
100 | 101 | if (err instanceof Error && 'code' in err && err.code !== 'ENOENT') { |
101 | | - throw new Error( |
102 | | - `Error when checking if typegen config file exists: ${legacyConfigPath}`, |
103 | | - { |
104 | | - cause: err, |
105 | | - }, |
106 | | - ) |
| 102 | + spin.fail() |
| 103 | + this.error(`Error when checking if typegen config file exists: ${legacyConfigPath}`, { |
| 104 | + exit: 1, |
| 105 | + }) |
107 | 106 | } |
108 | 107 | } |
109 | 108 |
|
@@ -154,7 +153,7 @@ export class TypegenGenerateCommand extends SanityCommand<typeof TypegenGenerate |
154 | 153 | } |
155 | 154 | } catch (err) { |
156 | 155 | spin.fail() |
157 | | - throw err |
| 156 | + this.error(`An error occured during config loading ${err}`, {exit: 1}) |
158 | 157 | } |
159 | 158 | } |
160 | 159 |
|
|
0 commit comments