Skip to content

Commit 35ff95d

Browse files
antfuclaude
andcommitted
fix: add throw keyword before logger.throw() for TypeScript control flow
TypeScript doesn't narrow types after `logger.CODE().throw()` because the return type inference doesn't propagate `never` through the chained call. Adding `throw` before the expression fixes control flow analysis. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7d0e98e commit 35ff95d

File tree

15 files changed

+29
-29
lines changed

15 files changed

+29
-29
lines changed

packages/core/src/node/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export async function createDevToolsContext(
167167
await plugin.devtools?.setup?.(context)
168168
}
169169
catch (error) {
170-
logger.DTK0014({ name: plugin.name }, { cause: error }).throw()
170+
throw logger.DTK0014({ name: plugin.name }, { cause: error }).throw()
171171
}
172172
}
173173

packages/core/src/node/host-commands.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class DevToolsCommandsHost implements DevToolsCommandsHostType {
1212

1313
register(command: DevToolsServerCommandInput): DevToolsCommandHandle {
1414
if (this.commands.has(command.id)) {
15-
logger.DTK0024({ id: command.id }).throw()
15+
throw logger.DTK0024({ id: command.id }).throw()
1616
}
1717
this.commands.set(command.id, command)
1818
this.events.emit('command:registered', this.toSerializable(command))
@@ -21,11 +21,11 @@ export class DevToolsCommandsHost implements DevToolsCommandsHostType {
2121
id: command.id,
2222
update: (patch: Partial<Omit<DevToolsServerCommandInput, 'id'>>) => {
2323
if ('id' in patch) {
24-
logger.DTK0025().throw()
24+
throw logger.DTK0025().throw()
2525
}
2626
const existing = this.commands.get(command.id)
2727
if (!existing) {
28-
logger.DTK0026({ id: command.id }).throw()
28+
throw logger.DTK0026({ id: command.id }).throw()
2929
}
3030
Object.assign(existing, patch)
3131
this.events.emit('command:registered', this.toSerializable(existing))
@@ -45,7 +45,7 @@ export class DevToolsCommandsHost implements DevToolsCommandsHostType {
4545
async execute(id: string, ...args: any[]): Promise<unknown> {
4646
const found = this.findCommand(id)
4747
if (!found) {
48-
logger.DTK0026({ id }).throw()
48+
throw logger.DTK0026({ id }).throw()
4949
}
5050
if (!found.handler) {
5151
throw new Error(`Command "${id}" has no handler (group-only command)`)

packages/core/src/node/host-docks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ export class DevToolsDockHost implements DevToolsDockHostType {
7373
update: (patch: Partial<T>) => void
7474
} {
7575
if (this.views.has(view.id) && !force) {
76-
logger.DTK0015({ id: view.id }).throw()
76+
throw logger.DTK0015({ id: view.id }).throw()
7777
}
7878
this.views.set(view.id, view)
7979
this.events.emit('dock:entry:updated', view)
8080

8181
return {
8282
update: (patch) => {
8383
if (patch.id && patch.id !== view.id) {
84-
logger.DTK0016().throw()
84+
throw logger.DTK0016().throw()
8585
}
8686
this.update(Object.assign(this.views.get(view.id)!, patch))
8787
},
@@ -90,7 +90,7 @@ export class DevToolsDockHost implements DevToolsDockHostType {
9090

9191
update(view: DevToolsDockUserEntry): void {
9292
if (!this.views.has(view.id)) {
93-
logger.DTK0017({ id: view.id }).throw()
93+
throw logger.DTK0017({ id: view.id }).throw()
9494
}
9595
this.views.set(view.id, view)
9696
this.events.emit('dock:entry:updated', view)

packages/core/src/node/host-functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class RpcFunctionsHost extends RpcFunctionsCollectorBase<DevToolsRpcServe
3131
...args: Args
3232
): Promise<Awaited<ReturnType<DevToolsRpcServerFunctions[T]>>> {
3333
if (!this.definitions.has(method as string)) {
34-
logger.DTK0020({ name: String(method) }).throw()
34+
throw logger.DTK0020({ name: String(method) }).throw()
3535
}
3636

3737
const handler = await this.getHandler(method)
@@ -66,7 +66,7 @@ export class RpcFunctionsHost extends RpcFunctionsCollectorBase<DevToolsRpcServe
6666

6767
getCurrentRpcSession(): DevToolsNodeRpcSession | undefined {
6868
if (!this._asyncStorage)
69-
logger.DTK0021().throw()
69+
throw logger.DTK0021().throw()
7070
return this._asyncStorage.getStore()
7171
}
7272
}

packages/core/src/node/host-terminals.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class DevToolsTerminalHost implements DevToolsTerminalHostType {
2020

2121
register(session: DevToolsTerminalSession): DevToolsTerminalSession {
2222
if (this.sessions.has(session.id)) {
23-
logger.DTK0018({ id: session.id }).throw()
23+
throw logger.DTK0018({ id: session.id }).throw()
2424
}
2525
this.sessions.set(session.id, session)
2626
this.bindStream(session)
@@ -30,7 +30,7 @@ export class DevToolsTerminalHost implements DevToolsTerminalHostType {
3030

3131
update(patch: PartialWithoutId<DevToolsTerminalSession>): void {
3232
if (!this.sessions.has(patch.id)) {
33-
logger.DTK0019({ id: patch.id }).throw()
33+
throw logger.DTK0019({ id: patch.id }).throw()
3434
}
3535
const session = this.sessions.get(patch.id)!
3636
Object.assign(session, patch)
@@ -85,7 +85,7 @@ export class DevToolsTerminalHost implements DevToolsTerminalHostType {
8585
terminal: Omit<DevToolsTerminalSessionBase, 'status'>,
8686
): Promise<DevToolsChildProcessTerminalSession> {
8787
if (this.sessions.has(terminal.id)) {
88-
logger.DTK0018({ id: terminal.id }).throw()
88+
throw logger.DTK0018({ id: terminal.id }).throw()
8989
}
9090
const { exec } = await import('tinyexec')
9191

packages/core/src/node/host-views.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ export class DevToolsViewHost implements DevToolsViewHostType {
1616

1717
hostStatic(baseUrl: string, distDir: string) {
1818
if (!existsSync(distDir)) {
19-
logger.DTK0022({ distDir }).throw()
19+
throw logger.DTK0022({ distDir }).throw()
2020
}
2121

2222
this.buildStaticDirs.push({ baseUrl, distDir })
2323

2424
if (this.context.viteConfig.command === 'serve') {
2525
if (!this.context.viteServer)
26-
logger.DTK0023().throw()
26+
throw logger.DTK0023().throw()
2727
this.context.viteServer.middlewares.use(
2828
baseUrl,
2929
sirv(distDir, {

packages/core/src/node/rpc-shared-state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function createRpcSharedStateServerHost(
4848
return sharedState.get(key)!
4949
}
5050
if (options?.initialValue === undefined && options?.sharedState === undefined) {
51-
logger.DTK0027({ key }).throw()
51+
throw logger.DTK0027({ key }).throw()
5252
}
5353
debug('new-state', key)
5454
const state = options.sharedState ?? createSharedState<T>({

packages/core/src/node/rpc/internal/docks-on-launch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export const docksOnLaunch = defineRpcFunction({
1414

1515
const entry = context.docks.values().find(entry => entry.id === entryId)
1616
if (!entry) {
17-
logger.DTK0030({ id: entryId }).throw()
17+
throw logger.DTK0030({ id: entryId }).throw()
1818
}
1919
if (entry.type !== 'launcher') {
20-
logger.DTK0031({ id: entryId }).throw()
20+
throw logger.DTK0031({ id: entryId }).throw()
2121
}
2222
try {
2323
context.docks.update({

packages/core/src/node/rpc/public/open-in-editor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const openInEditor = defineRpcFunction({
1313

1414
// Prevent escaping the workspace root
1515
if (rel.startsWith('..') || rel.includes('\0')) {
16-
logger.DTK0028().throw()
16+
throw logger.DTK0028().throw()
1717
}
1818

1919
await import('launch-editor').then(r => r.default(resolved))

packages/core/src/node/rpc/public/open-in-finder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const openInFinder = defineRpcFunction({
1313

1414
// Ensure the path stays within workspace root
1515
if (rel.startsWith('..') || rel.includes('\0')) {
16-
logger.DTK0029().throw()
16+
throw logger.DTK0029().throw()
1717
}
1818

1919
await import('open').then(r => r.default(resolved))

0 commit comments

Comments
 (0)