refactor: explicit returns + void floating promises (T3.a typeaware sweep) (#756)

Cluster T3.a — mechanical fixes for consistent-return and no-floating-promises.

Files touched (15):
- server/shared/tool-call-display.ts — default throw in buildCanonicalDetailDisplay switch
- server/agent/prompt-attachments.ts — default throw in renderPromptAttachmentAsText switch
- server/workspace-directory.ts — default throw in getSortValue switch
- server/agent/mcp-server.ts — default throw in mcpCreateWorktreeInput switch
- server/terminal/terminal-session-controller.ts — default return in dispatch switch
- server/daemon-e2e/agent-configs.ts — default return false in isProviderAvailable switch
- server/agent/agent-manager.ts — void dispatchSessionEvent fire-and-forget call
- server/agent/mcp-shared.ts — void 4 notify() floating calls
- app/agent-status-bar.utils.ts — default throw in getStatusSelectorHint switch
- app/keyboard-shortcuts.ts — default throw in resolvePayload switch
- app/resolve-agent-form.ts — default throw in resolveAgentForm switch
- app/ui/dropdown-menu.tsx — void .then() + return undefined for promise/always-return
- app/use-agent-form-state.ts — void refreshSnapshot() floating call
- cli/worktree/create.ts — default throw in toDaemonCreateInput switch
- cli/onboard.ts — return process.exit(1) to satisfy consistent-return in catch

Deferred (outside 15-file cap or in EXCLUDE list):
- server/worktree-session.ts — getSortValue (same pattern, cap reached)
- Multiple files with other errors (unbound-method, unsafe-type-assertion) are separate clusters
This commit is contained in:
Mohamed Boudra
2026-05-05 19:58:56 +07:00
parent df5c59263e
commit eb6d19969d
15 changed files with 31 additions and 11 deletions
@@ -11,6 +11,8 @@ export function getStatusSelectorHint(selector: ExplainedStatusSelector): string
return "Change model"; return "Change model";
case "mode": case "mode":
return "Change permission mode"; return "Change permission mode";
default:
throw new Error("unreachable");
} }
} }
@@ -445,7 +445,7 @@ export function DropdownMenuContent({
setTriggerRect(null); setTriggerRect(null);
setContentSize(null); setContentSize(null);
setPosition(null); setPosition(null);
return; return undefined;
} }
// Capture status bar height synchronously before async measurement. // Capture status bar height synchronously before async measurement.
@@ -454,8 +454,8 @@ export function DropdownMenuContent({
const statusBarHeight = Platform.OS === "android" ? (StatusBar.currentHeight ?? 0) : 0; const statusBarHeight = Platform.OS === "android" ? (StatusBar.currentHeight ?? 0) : 0;
let cancelled = false; let cancelled = false;
measureElement(triggerRef.current).then((rect) => { void measureElement(triggerRef.current).then((rect) => {
if (cancelled) return; if (cancelled) return undefined;
// On Android with statusBarTranslucent, measureInWindow returns coordinates // On Android with statusBarTranslucent, measureInWindow returns coordinates
// relative to below the status bar, but Modal content starts from screen top. // relative to below the status bar, but Modal content starts from screen top.
// Add status bar height to align coordinate systems (same as react-native-popover-view). // Add status bar height to align coordinate systems (same as react-native-popover-view).
@@ -463,7 +463,7 @@ export function DropdownMenuContent({
...rect, ...rect,
y: rect.y + statusBarHeight, y: rect.y + statusBarHeight,
}); });
return; return undefined;
}); });
return () => { return () => {
@@ -553,5 +553,7 @@ export function resolveAgentForm(
case "RESET": case "RESET":
return { ...state, userModified: INITIAL_USER_MODIFIED }; return { ...state, userModified: INITIAL_USER_MODIFIED };
default:
throw new Error("unreachable");
} }
} }
@@ -459,7 +459,7 @@ export function useAgentFormState(options: UseAgentFormStateOptions = {}): UseAg
}, []); }, []);
const refreshProviderModels = useCallback(() => { const refreshProviderModels = useCallback(() => {
refreshSnapshot(); void refreshSnapshot();
}, [refreshSnapshot]); }, [refreshSnapshot]);
const refetchProviderModelsIfStale = useCallback(() => { const refetchProviderModelsIfStale = useCallback(() => {
@@ -1055,6 +1055,8 @@ function resolvePayload(
return { delta: def.delta }; return { delta: def.delta };
case "message-input": case "message-input":
return { kind: def.kind }; return { kind: def.kind };
default:
throw new Error("unreachable");
} }
} }
+1 -1
View File
@@ -432,7 +432,7 @@ async function waitForDaemonReadyWithUi(args: {
} else { } else {
log.error(message); log.error(message);
} }
process.exit(1); return process.exit(1);
} }
} }
@@ -123,6 +123,8 @@ export function toDaemonCreateInput(parsed: ParsedWorktreeCreateInput) {
action: "checkout" as const, action: "checkout" as const,
githubPrNumber: parsed.target.prNumber, githubPrNumber: parsed.target.prNumber,
}; };
default:
throw new Error("unreachable");
} }
} }
@@ -1647,7 +1647,7 @@ export class AgentManager {
{ agentId, foregroundTurnId }, { agentId, foregroundTurnId },
"cancelAgentRun: foreground turn still active after timeout, force-canceling", "cancelAgentRun: foreground turn still active after timeout, force-canceling",
); );
this.dispatchSessionEvent(agent, { void this.dispatchSessionEvent(agent, {
type: "turn_canceled", type: "turn_canceled",
provider: agent.provider, provider: agent.provider,
reason: "interrupted", reason: "interrupted",
@@ -2104,6 +2104,8 @@ function mcpCreateWorktreeInput(
return { return {
input: { ...base, action: "checkout", githubPrNumber: target.prNumber }, input: { ...base, action: "checkout", githubPrNumber: target.prNumber },
}; };
default:
throw new Error("unreachable");
} }
} }
@@ -327,11 +327,11 @@ export function setupFinishNotification(params: SetupFinishNotificationParams):
return; return;
} }
if (event.agent.lifecycle === "error") { if (event.agent.lifecycle === "error") {
notify("errored"); void notify("errored");
return; return;
} }
if (event.agent.lifecycle === "idle" && hasSeenRunning) { if (event.agent.lifecycle === "idle" && hasSeenRunning) {
notify("finished"); void notify("finished");
return; return;
} }
if (event.agent.lifecycle === "closed") { if (event.agent.lifecycle === "closed") {
@@ -343,7 +343,7 @@ export function setupFinishNotification(params: SetupFinishNotificationParams):
} }
if (event.event.type === "permission_requested") { if (event.event.type === "permission_requested") {
notify("needs permission"); void notify("needs permission");
} }
}, },
{ agentId: childAgentId, replayState: false }, { agentId: childAgentId, replayState: false },
@@ -362,7 +362,7 @@ export function setupFinishNotification(params: SetupFinishNotificationParams):
if (childSnapshot.lifecycle === "running") { if (childSnapshot.lifecycle === "running") {
hasSeenRunning = true; hasSeenRunning = true;
} else if (childSnapshot.lifecycle === "error") { } else if (childSnapshot.lifecycle === "error") {
notify("errored"); void notify("errored");
} }
} }
@@ -54,6 +54,8 @@ export function renderPromptAttachmentAsText(attachment: AgentAttachment): strin
}); });
return lines.join("\n"); return lines.join("\n");
} }
default:
throw new Error("unreachable");
} }
} }
@@ -134,6 +134,8 @@ export function isProviderAvailable(provider: AgentProvider): Promise<boolean> {
Boolean(process.env.OPENROUTER_API_KEY) || Boolean(process.env.OPENROUTER_API_KEY) ||
existsSync(join(homedir(), ".pi", "agent", "auth.json"))) existsSync(join(homedir(), ".pi", "agent", "auth.json")))
); );
default:
return false;
} }
})(); })();
@@ -116,6 +116,8 @@ export class WorkspaceDirectory {
return workspace.name.toLocaleLowerCase(); return workspace.name.toLocaleLowerCase();
case "project_id": case "project_id":
return workspace.projectId.toLocaleLowerCase(); return workspace.projectId.toLocaleLowerCase();
default:
throw new Error("unreachable");
} }
}, },
}); });
@@ -122,6 +122,8 @@ function buildCanonicalDetailDisplay(input: ToolCallDisplayInput): DetailDisplay
}; };
case "unknown": case "unknown":
return {}; return {};
default:
throw new Error("unreachable");
} }
} }
@@ -145,6 +145,8 @@ export class TerminalSessionController {
return this.handleKillTerminalRequest(msg); return this.handleKillTerminalRequest(msg);
case "capture_terminal_request": case "capture_terminal_request":
return this.handleCaptureTerminalRequest(msg); return this.handleCaptureTerminalRequest(msg);
default:
return undefined;
} }
} }