Skip to content

Commit a31362f

Browse files
author
dmungamuri
committed
feat: improve error capture UX with filtered stack traces and cleaner logs
- Remove verbose console logs on error capture server startup - Add server-side cleanup for _clientParsedStack field (client-only data) - Keep filtered stack traces (show local source only, hide framework code) - Improve code documentation and comments
1 parent d95fc3b commit a31362f

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

src/lwc-dev-server/errorMiddleware.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ export function createErrorMiddleware(
7272

7373
const error = payload;
7474

75+
// Clean up client-only fields (used for browser logging, not needed on server)
76+
// eslint-disable-next-line no-underscore-dangle
77+
if ('_clientParsedStack' in error.error) {
78+
// eslint-disable-next-line no-underscore-dangle
79+
delete (error.error as Record<string, unknown>)._clientParsedStack;
80+
}
81+
7582
// Enhance stack trace with project context
7683
if (error.error.stack && error.error.sanitizedStack.length === 0) {
7784
error.error.sanitizedStack = parseStackTrace(error.error.stack, projectRoot);
@@ -84,7 +91,7 @@ export function createErrorMiddleware(
8491
if (logToConsole) {
8592
const formatted = formatErrorForCLI(error, {
8693
colorize: true,
87-
showFullStack: false,
94+
showFullStack: false, // Only show local source frames, hide framework/library code
8895
compact: false,
8996
});
9097
// eslint-disable-next-line no-console

src/lwc-dev-server/index.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ async function createLWCServerConfig(
4747

4848
const ports = serverPorts ??
4949
(await ConfigUtils.getLocalDevServerPorts()) ?? {
50-
httpPort: LOCAL_DEV_SERVER_DEFAULT_HTTP_PORT,
51-
httpsPort: LOCAL_DEV_SERVER_DEFAULT_HTTP_PORT + 1,
52-
};
50+
httpPort: LOCAL_DEV_SERVER_DEFAULT_HTTP_PORT,
51+
httpsPort: LOCAL_DEV_SERVER_DEFAULT_HTTP_PORT + 1,
52+
};
5353

5454
const serverConfig: ServerConfig = {
5555
rootDir,
@@ -107,31 +107,19 @@ export async function startLWCServer(
107107
localhostOnly: true, // Bind to localhost only for security
108108
});
109109

110-
// eslint-disable-next-line no-console
111-
console.log('\n✅ [ErrorCapture] Error capture system initialized');
112-
// eslint-disable-next-line no-console
113-
console.log(`📡 [ErrorCapture] LWC Dev Server (WebSocket): ws://localhost:${config.port}`);
114-
// eslint-disable-next-line no-console
115-
console.log(`🔍 [ErrorCapture] Error Capture Server (HTTP): http://localhost:${errorCapturePort}`);
116-
// eslint-disable-next-line no-console
117-
console.log('💡 [ErrorCapture] Tip: Errors clear automatically on server restart');
118-
// eslint-disable-next-line no-console
119-
console.log(` Or manually: curl -X DELETE http://localhost:${errorCapturePort}/_dev/errors\n`);
120110
logger.info('[ErrorCapture] Error capture system initialized');
121111
} catch (err) {
122112
// eslint-disable-next-line no-console
123113
console.log(
124-
`\n⚠️ [ErrorCapture] Failed to start error capture server on port ${errorCapturePort}: ${
125-
err instanceof Error ? err.message : String(err)
114+
`\n⚠️ [ErrorCapture] Failed to start error capture server on port ${errorCapturePort}: ${err instanceof Error ? err.message : String(err)
126115
}`
127116
);
128117
// eslint-disable-next-line no-console
129118
console.log(
130119
'⚠️ [ErrorCapture] Error capture will not be available. This does not affect LWC dev server functionality.\n'
131120
);
132121
logger.warn(
133-
`[ErrorCapture] Failed to start error capture server on port ${errorCapturePort}: ${
134-
err instanceof Error ? err.message : String(err)
122+
`[ErrorCapture] Failed to start error capture server on port ${errorCapturePort}: ${err instanceof Error ? err.message : String(err)
135123
}`
136124
);
137125
}

0 commit comments

Comments
 (0)