fix: log removeDevice failures with structured error fields

Apply reviewer feedback from PR #1283 review:
- Log err.name and err.message instead of raw err object to avoid
  {} serialization in JSON-based loggers, consistent with teardown()
  and connect() error handling patterns in the same file
- Reformat long chained call in connect() for readability
This commit is contained in:
copilot-swe-agent[bot]
2026-07-14 02:03:22 +00:00
committed by GitHub
parent b929ed4203
commit 8158b5e10b

View File

@@ -88,7 +88,15 @@ export function useConnections() {
if (conn?.meshDeviceId) {
try {
useDeviceStore.getState().removeDevice(conn.meshDeviceId);
} catch {}
} catch (e) {
const err = e as Error;
log.warn("removeDevice failed during removeConnection", {
id,
meshDeviceId: conn.meshDeviceId,
name: err?.name,
message: err?.message,
});
}
}
meshRegistry.unregister(id);
removeSavedConnectionFromStore(id);
@@ -249,7 +257,9 @@ export function useConnections() {
// Read from the live store, not the memoized `connections` closure: callers
// such as addConnectionAndConnect() add a connection and connect to it in the
// same tick, before this hook re-renders, so the closure would be stale.
const conn = useDeviceStore.getState().savedConnections.find((c) => c.id === id);
const conn = useDeviceStore
.getState()
.savedConnections.find((c) => c.id === id);
if (!conn) {
log.warn("connect: unknown connection id", { id });
return false;