refactor(errors): surface 57 deferred catch-and-swallow sites via logger
The earlier sweep cleaned the hot path (worker/runtime/automation/api-
server/ipc core — 59 sites). This pass finishes the deferred long tail:
main/* services, database/* CRUD modules, api-server/* routes, ipc-*
handlers, thread-integration, automation helpers, browser, skills.
Default strategy: catch (error) { logger.warn("[module] context:", ...) }
— preserve current behavior, make the failure visible instead of
silently hidden. Widened 3 logger interface signatures to include warn
where callers only passed info/error previously (thread-helpers,
host-environment-service, ipc-domain-common).
Legitimate boundaries left intact: JSON.parse on untrusted input, DNS
resolver no-records paths, explicit safe* helpers (safeJson, parseJson,
parseTriggerDetail), URL-parse predicates, and `<unserialisable>`
fallbacks inside the prompt-builder summarisers. Each kept catch now
either has a reason in context or is a documented safe* helper.
Tests adjusted only where test-constructed no-op loggers needed a warn
stub (message-dispatch, company-mode-switch, ipc-agent-graph-handlers).
With the earlier pass, AgentCompany no longer has silently-swallowing
catch blocks in main-process or renderer business code.
This commit is contained in:
1 parent
ecd1bc2e33
commit
40040b3dd2
46 files changed
+209
-113
No files matched your search
@@ -13,7 +13,8 @@ export function registerAgentControlRoutes(server: AgentApiServer) {
|
||||
const targetAgent = (() => {
|
||||
try {
|
||||
return db.getAgent(targetAgentId);
|
||||
} catch {
|
||||
} catch (err) {
|
||||
log.warn(`[api/agent-control] getAgent failed for ${targetAgentId}:`, err instanceof Error ? err.message : String(err));
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
@@ -52,7 +53,8 @@ export function registerAgentControlRoutes(server: AgentApiServer) {
|
||||
let targetAgent;
|
||||
try {
|
||||
targetAgent = db.getAgent(targetAgentId);
|
||||
} catch {
|
||||
} catch (err) {
|
||||
log.warn(`[api/agent-control] getAgent failed for heartbeat ${targetAgentId}:`, err instanceof Error ? err.message : String(err));
|
||||
targetAgent = null;
|
||||
}
|
||||
if (!targetAgent || targetAgent.companyId !== token.companyId) {
|
||||
|
||||
@@ -156,7 +156,8 @@ export function registerAgentRoutes(server: AgentApiServer) {
|
||||
let agent;
|
||||
try {
|
||||
agent = db.getAgent(requireParam(params, "agentId"));
|
||||
} catch {
|
||||
} catch (err) {
|
||||
log.warn(`[api/agents] getAgent failed:`, err instanceof Error ? err.message : String(err));
|
||||
server.json(res, 404, { error: "Agent not found" });
|
||||
return;
|
||||
}
|
||||
@@ -262,7 +263,8 @@ export function registerAgentRoutes(server: AgentApiServer) {
|
||||
const connectorRecord = (() => {
|
||||
try {
|
||||
return db.getConnector(input.connectorId);
|
||||
} catch {
|
||||
} catch (err) {
|
||||
log.warn(`[api/agents] getConnector failed for ${input.connectorId}:`, err instanceof Error ? err.message : String(err));
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
@@ -305,7 +307,8 @@ export function registerAgentRoutes(server: AgentApiServer) {
|
||||
? (() => {
|
||||
try {
|
||||
return db.getAgent(resolvedReportsTo).name;
|
||||
} catch {
|
||||
} catch (err) {
|
||||
log.warn(`[api/agents] getAgent failed for manager ${resolvedReportsTo}:`, err instanceof Error ? err.message : String(err));
|
||||
return resolvedReportsTo;
|
||||
}
|
||||
})()
|
||||
|
||||
@@ -38,7 +38,8 @@ export function registerMeetingRoutes(server: AgentApiServer) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
} catch (err) {
|
||||
log.warn(`[api/meetings] participantAgentIds JSON parse failed:`, err instanceof Error ? err.message : String(err));
|
||||
server.json(res, 400, { error: "participantAgentIds must be a JSON array of agent ids" });
|
||||
return;
|
||||
}
|
||||
@@ -95,7 +96,8 @@ export function registerMeetingRoutes(server: AgentApiServer) {
|
||||
if (data.actionItemsJson) {
|
||||
try {
|
||||
actionItems = JSON.parse(data.actionItemsJson) as Array<{ title?: string; assigneeAgentId?: string; description?: string }>;
|
||||
} catch {
|
||||
} catch (err) {
|
||||
log.warn(`[api/meetings] actionItemsJson parse failed:`, err instanceof Error ? err.message : String(err));
|
||||
server.json(res, 400, { error: "actionItemsJson must be valid JSON" });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import log from "electron-log/main.js";
|
||||
import { agentMessageInputSchema } from "@shared/contracts";
|
||||
import { dispatchAgentMessage } from "../message-dispatch";
|
||||
import { requireParam, type AgentApiServer } from "./server-core";
|
||||
@@ -59,7 +60,8 @@ export function registerMessageRoutes(server: AgentApiServer) {
|
||||
}
|
||||
|
||||
server.json(res, 201, comment);
|
||||
} catch {
|
||||
} catch (err) {
|
||||
log.warn(`[api/messages] addComment failed:`, err instanceof Error ? err.message : String(err));
|
||||
server.json(res, 404, { error: "Task not found" });
|
||||
}
|
||||
});
|
||||
@@ -71,7 +73,8 @@ export function registerMessageRoutes(server: AgentApiServer) {
|
||||
server.json(res, 404, { error: "Task not found" });
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
} catch (err) {
|
||||
log.warn(`[api/messages] getTask failed for comments list:`, err instanceof Error ? err.message : String(err));
|
||||
server.json(res, 404, { error: "Task not found" });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,8 @@ export function registerTaskRoutes(server: AgentApiServer) {
|
||||
return;
|
||||
}
|
||||
server.json(res, 200, task);
|
||||
} catch {
|
||||
} catch (err) {
|
||||
log.warn(`[api/tasks] getTask failed:`, err instanceof Error ? err.message : String(err));
|
||||
server.json(res, 404, { error: "Task not found" });
|
||||
}
|
||||
});
|
||||
@@ -73,7 +74,8 @@ export function registerTaskRoutes(server: AgentApiServer) {
|
||||
let task;
|
||||
try {
|
||||
task = db.getTask(requireParam(params, "issueId"));
|
||||
} catch {
|
||||
} catch (err) {
|
||||
log.warn(`[api/tasks] getTask failed for checkout:`, err instanceof Error ? err.message : String(err));
|
||||
server.json(res, 404, { error: "Task not found" });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import log from "electron-log/main.js";
|
||||
import { z } from "zod";
|
||||
import { goalInputSchema, projectInputSchema } from "@shared/contracts";
|
||||
import { canManageGoal, canManageProject } from "../agent-permissions";
|
||||
@@ -102,7 +103,8 @@ export function registerWorkGraphRoutes(server: AgentApiServer) {
|
||||
});
|
||||
onDomainChanged();
|
||||
server.json(res, 200, { ok: true });
|
||||
} catch {
|
||||
} catch (err) {
|
||||
log.warn(`[api/work-graph] Failed to update project:`, err instanceof Error ? err.message : String(err));
|
||||
server.json(res, 500, { error: "Failed to update project" });
|
||||
}
|
||||
});
|
||||
@@ -187,7 +189,8 @@ export function registerWorkGraphRoutes(server: AgentApiServer) {
|
||||
});
|
||||
onDomainChanged();
|
||||
server.json(res, 200, { ok: true });
|
||||
} catch {
|
||||
} catch (err) {
|
||||
log.warn(`[api/work-graph] Failed to update goal:`, err instanceof Error ? err.message : String(err));
|
||||
server.json(res, 500, { error: "Failed to update goal" });
|
||||
}
|
||||
});
|
||||
@@ -241,7 +244,8 @@ export function registerWorkGraphRoutes(server: AgentApiServer) {
|
||||
});
|
||||
onDomainChanged();
|
||||
server.json(res, 201, { id });
|
||||
} catch {
|
||||
} catch (err) {
|
||||
log.warn(`[api/work-graph] Invalid sprint data:`, err instanceof Error ? err.message : String(err));
|
||||
server.json(res, 400, { error: "Invalid sprint data" });
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user