-
Notifications
You must be signed in to change notification settings - Fork 0
🧹 [Code Health] Replace console.log with structured Logger in dap-client.ts #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import { | |
| AgentInfo, | ||
| Job, | ||
| } from '../protocol/types.js'; | ||
| import { Logger } from '../utils/logger.js'; | ||
|
|
||
| export interface DAPClientConfig { | ||
| relayUrl: string; | ||
|
|
@@ -24,6 +25,8 @@ export interface DAPClientConfig { | |
|
|
||
| export type MessageHandler = (msg: DAPMessage) => Promise<void>; | ||
|
|
||
| const clientLogger = new Logger('dap-client'); | ||
|
|
||
| export class DAPClient { | ||
| private config: DAPClientConfig; | ||
| private socket: WebSocket | null = null; | ||
|
|
@@ -57,7 +60,7 @@ export class DAPClient { | |
| this.socket = new WebSocket(url.toString()); | ||
|
|
||
| this.socket.onopen = () => { | ||
| console.log(`[DAPClient] Connected to ${this.config.relayUrl}`); | ||
| clientLogger.info(`Connected to ${this.config.relayUrl}`); | ||
|
|
||
| const registerMsg = { | ||
| action: 'register', | ||
|
|
@@ -79,18 +82,18 @@ export class DAPClient { | |
| const msg = JSON.parse(event.data) as DAPMessage; | ||
| await this.handleMessage(msg); | ||
| } catch (err) { | ||
| console.error('[DAPClient] Message handling error:', err); | ||
| clientLogger.error('Message handling error', { error: err }); | ||
| } | ||
| }; | ||
|
|
||
| this.socket.onclose = (event) => { | ||
| console.log(`[DAPClient] Disconnected: ${event.code}`); | ||
| clientLogger.info(`Disconnected: ${event.code}`); | ||
| this.connected = false; | ||
| this.scheduleReconnect(); | ||
| }; | ||
|
|
||
| this.socket.onerror = (err) => { | ||
| console.error('[DAPClient] Connection error:', err); | ||
| clientLogger.error('Connection error', { error: err }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the other error logging instances, passing the clientLogger.error('Connection error', {
error: err instanceof Error ? { message: err.message, stack: err.stack } : err,
}); |
||
| reject(err); | ||
| }; | ||
| }); | ||
|
|
@@ -122,13 +125,13 @@ export class DAPClient { | |
| 60000 | ||
| ); | ||
|
|
||
| console.log(`[DAPClient] Reconnecting in ${delay}ms (attempt ${this.reconnectAttempts})`); | ||
| clientLogger.info(`Reconnecting in ${delay}ms (attempt ${this.reconnectAttempts})`); | ||
|
|
||
| this.reconnectTimer = setTimeout(async () => { | ||
| this.reconnectTimer = undefined; | ||
| try { | ||
| await this.connect(); | ||
| console.log('[DAPClient] Reconnected'); | ||
| clientLogger.info('Reconnected'); | ||
| } catch { | ||
| // Will try again | ||
| } | ||
|
|
@@ -152,7 +155,7 @@ export class DAPClient { | |
| try { | ||
| await handler(msg); | ||
| } catch (err) { | ||
| console.error('[DAPClient] Handler error:', err); | ||
| clientLogger.error('Handler error', { error: err }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passing the caught clientLogger.error('Handler error', {
error: err instanceof Error ? { message: err.message, stack: err.stack } : err,
}); |
||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In JavaScript/TypeScript, standard
Errorproperties (likemessageandstack) are non-enumerable. When you pass anErrorobject directly inside the metadata object toJSON.stringify(which is what the structuredLoggerdoes internally), it serializes to{}. This means the actual error message and stack trace will be completely lost in your structured logs.To fix this, convert the error to a plain object or extract its properties before logging.