Skip to content

Commit e85ba89

Browse files
committed
fix: fix lint error
1 parent 99b8c37 commit e85ba89

File tree

2 files changed

+66
-32
lines changed

2 files changed

+66
-32
lines changed

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ import { promisify } from "util";
3232
export async function activate(context: vscode.ExtensionContext): Promise<any> {
3333
await initializeFromJsonFile(context.asAbsolutePath("./package.json"));
3434
await initExpService(context);
35-
35+
3636
// Register No-Config Debug functionality
3737
const noConfigDisposable = await registerNoConfigDebug(
3838
context.environmentVariableCollection,
3939
context.extensionPath
4040
);
4141
context.subscriptions.push(noConfigDisposable);
42-
42+
4343
return instrumentOperation("activation", initializeExtension)(context);
4444
}
4545

src/noConfigDebugInit.ts

Lines changed: 64 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import * as path from 'path';
66
import * as crypto from 'crypto';
77
import * as vscode from 'vscode';
88

9+
import { sendInfo, sendError } from "vscode-extension-telemetry-wrapper";
10+
911
/**
1012
* Registers the configuration-less debugging setup for the extension.
1113
*
@@ -33,8 +35,12 @@ export async function registerNoConfigDebug(
3335
workspaceString = vscode.workspace.workspaceFolders?.map((e) => e.uri.fsPath).join(';');
3436
}
3537
if (!workspaceString) {
36-
console.error('[Java Debug] No workspace folder found');
37-
return Promise.resolve(new vscode.Disposable(() => {}));
38+
const error: Error = {
39+
name: "NoConfigDebugError",
40+
message: '[Java Debug] No workspace folder found',
41+
};
42+
sendError(error);
43+
return Promise.resolve(new vscode.Disposable(() => { }));
3844
}
3945

4046
// create a stable hash for the workspace folder, reduce terminal variable churn
@@ -52,7 +58,11 @@ export async function registerNoConfigDebug(
5258
// remove endpoint file in the temp directory if it exists (async to avoid blocking)
5359
if (fs.existsSync(tempFilePath)) {
5460
fs.promises.unlink(tempFilePath).catch((err) => {
55-
console.error(`[Java Debug] Failed to cleanup old endpoint file: ${err}`);
61+
const error: Error = {
62+
name: "NoConfigDebugError",
63+
message: `[Java Debug] Failed to cleanup old endpoint file: ${err}`,
64+
};
65+
sendError(error);
5666
});
5767
}
5868
}
@@ -80,52 +90,60 @@ export async function registerNoConfigDebug(
8090
const fileSystemWatcher = vscode.workspace.createFileSystemWatcher(
8191
new vscode.RelativePattern(tempDirPath, '**/*.txt')
8292
);
83-
93+
8494
// Track active debug sessions to prevent duplicates
8595
const activeDebugSessions = new Set<number>();
86-
96+
8797
// Handle both file creation and modification to support multiple runs
8898
const handleEndpointFile = async (uri: vscode.Uri) => {
89-
console.log('[Java Debug] No-config debug session detected');
90-
9199
const filePath = uri.fsPath;
92-
100+
93101
// Add a small delay to ensure file is fully written
94102
// File system events can fire before write is complete
95103
await new Promise(resolve => setTimeout(resolve, 100));
96-
104+
97105
fs.readFile(filePath, (err, data) => {
98106
if (err) {
99-
console.error(`[Java Debug] Error reading endpoint file: ${err}`);
107+
const error: Error = {
108+
name: "NoConfigDebugError",
109+
message: `[Java Debug] No-config debug failed: file_read_error - ${err}`,
110+
};
111+
sendError(error);
100112
return;
101113
}
102114
try {
103115
// parse the client port
104116
const dataParse = data.toString();
105117
const jsonData = JSON.parse(dataParse);
106-
118+
107119
// Validate JSON structure
108120
if (!jsonData || typeof jsonData !== 'object' || !jsonData.client) {
109-
console.error(`[Java Debug] Invalid endpoint file format: ${dataParse}`);
121+
const error: Error = {
122+
name: "NoConfigDebugError",
123+
message: `[Java Debug] No-config debug failed: invalid_format - ${dataParse}`,
124+
};
125+
sendError(error);
110126
return;
111127
}
112-
128+
113129
const clientPort = jsonData.client.port;
114-
130+
115131
// Validate port number
116132
if (!clientPort || typeof clientPort !== 'number' || clientPort < 1 || clientPort > 65535) {
117-
console.error(`[Java Debug] Invalid port number: ${clientPort}`);
133+
const error: Error = {
134+
name: "NoConfigDebugError",
135+
message: `[Java Debug] No-config debug failed: invalid_port - ${clientPort}`,
136+
};
137+
sendError(error);
118138
return;
119139
}
120-
140+
121141
// Check if we already have an active session for this port
122142
if (activeDebugSessions.has(clientPort)) {
123-
console.log(`[Java Debug] Debug session already active for port ${clientPort}, skipping`);
143+
// Skip duplicate session silently - this is expected behavior
124144
return;
125145
}
126-
127-
console.log(`[Java Debug] Parsed JDWP port: ${clientPort}`);
128-
146+
129147
// Mark this port as active
130148
activeDebugSessions.add(clientPort);
131149

@@ -147,43 +165,59 @@ export async function registerNoConfigDebug(
147165
).then(
148166
(started) => {
149167
if (started) {
150-
console.log('[Java Debug] Successfully started no-config debug session');
168+
// Send telemetry only on successful session start with port info
169+
sendInfo('', { message: '[Java Debug] No-config debug session started', port: clientPort });
151170
// Clean up the endpoint file after successful debug session start (async)
152171
if (fs.existsSync(filePath)) {
153-
fs.promises.unlink(filePath).then(() => {
154-
console.log('[Java Debug] Cleaned up endpoint file');
155-
}).catch((cleanupErr) => {
156-
console.error(`[Java Debug] Failed to cleanup endpoint file: ${cleanupErr}`);
172+
fs.promises.unlink(filePath).catch((cleanupErr) => {
173+
// Cleanup failure is non-critical, just log for debugging
174+
const error: Error = {
175+
name: "NoConfigDebugError",
176+
message: `[Java Debug] No-config debug failed: cleanup_error - ${cleanupErr}`,
177+
};
178+
sendError(error);
157179
});
158180
}
159181
} else {
160-
console.error('[Java Debug] Error starting debug session, session not started.');
182+
const error: Error = {
183+
name: "NoConfigDebugError",
184+
message: `[Java Debug] No-config debug failed: attach_failed - port ${clientPort}`,
185+
};
186+
sendError(error);
161187
// Remove from active sessions on failure
162188
activeDebugSessions.delete(clientPort);
163189
}
164190
},
165191
(error) => {
166-
console.error(`[Java Debug] Error starting debug session: ${error}`);
192+
const attachError: Error = {
193+
name: "NoConfigDebugError",
194+
message: `[Java Debug] No-config debug failed: attach_error - port ${clientPort} - ${error}`,
195+
};
196+
sendError(attachError);
167197
// Remove from active sessions on error
168198
activeDebugSessions.delete(clientPort);
169199
},
170200
);
171201
} catch (parseErr) {
172-
console.error(`[Java Debug] Error parsing JSON: ${parseErr}`);
202+
const error: Error = {
203+
name: "NoConfigDebugError",
204+
message: `[Java Debug] No-config debug failed: parse_error - ${parseErr}`,
205+
};
206+
sendError(error);
173207
}
174208
});
175209
};
176210

177211
// Listen for both file creation and modification events
178212
const fileCreationEvent = fileSystemWatcher.onDidCreate(handleEndpointFile);
179213
const fileChangeEvent = fileSystemWatcher.onDidChange(handleEndpointFile);
180-
214+
181215
// Clean up active sessions when debug session ends
182216
const debugSessionEndListener = vscode.debug.onDidTerminateDebugSession((session) => {
183217
if (session.name === 'Attach to Java (No-Config)' && session.configuration.port) {
184218
const port = session.configuration.port;
185219
activeDebugSessions.delete(port);
186-
console.log(`[Java Debug] Debug session ended for port ${port}`);
220+
// Session end is normal operation, no telemetry needed
187221
}
188222
});
189223

0 commit comments

Comments
 (0)