Skip to content

Commit 95f78ec

Browse files
[VSC-1769] Bugfixes for v1.11.0 based on Telemetry (#1675)
* rm serial port chip id error telemetry use node os arch check binary is in path before version cmd * fix platform info test * more fixes in child process and telemetry ignore msg
1 parent 5cbaa45 commit 95f78ec

File tree

10 files changed

+93
-76
lines changed

10 files changed

+93
-76
lines changed

src/PlatformInformation.ts

Lines changed: 26 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,44 @@
1313
// limitations under the License.
1414

1515
import * as os from "os";
16-
import * as utils from "./utils";
1716

1817
export class PlatformInformation {
19-
public static GetPlatformInformation(): Promise<PlatformInformation> {
18+
public static GetPlatformInformation(): PlatformInformation {
2019
const platform: string = os.platform();
21-
let architecturePromise: Promise<string>;
20+
const arch = os.arch();
2221

22+
// Map os.arch() values to expected architecture strings
23+
let architecture: string;
2324
switch (platform) {
2425
case "win32":
25-
architecturePromise = PlatformInformation.GetWindowsArchitecture();
26+
if (arch === "x64") {
27+
architecture = "x86_x64";
28+
} else if (arch === "ia32") {
29+
architecture = "x86";
30+
} else {
31+
architecture = "Unknown";
32+
}
2633
break;
2734
case "linux":
28-
architecturePromise = PlatformInformation.GetUnixArchitecture();
29-
break;
3035
case "darwin":
31-
architecturePromise = PlatformInformation.GetUnixArchitecture();
36+
if (arch === "x64") {
37+
architecture = "x64";
38+
} else if (arch === "ia32") {
39+
architecture = "x86";
40+
} else if (arch === "arm64") {
41+
architecture = "arm64";
42+
} else if (arch === "arm") {
43+
architecture = "armhf";
44+
} else {
45+
architecture = arch;
46+
}
47+
break;
3248
default:
49+
architecture = "Unknown";
3350
break;
3451
}
35-
return Promise.all<string>([architecturePromise]).then(([architecture]) => {
36-
return new PlatformInformation(platform, architecture);
37-
});
52+
53+
return new PlatformInformation(platform, architecture);
3854
}
3955

4056
public get platformToUse(): string {
@@ -75,48 +91,5 @@ export class PlatformInformation {
7591
}
7692
}
7793

78-
public static GetUnknownArchitecture(): string {
79-
return "Unknown";
80-
}
81-
82-
public static GetUnixArchitecture(): Promise<string> {
83-
const command = "uname";
84-
const args = ["-m"];
85-
return utils
86-
.execChildProcess(command, args, utils.extensionContext.extensionPath)
87-
.then((architecture) => {
88-
if (architecture) {
89-
return architecture.trim();
90-
}
91-
});
92-
}
93-
94-
private static GetWindowsArchitecture(): Promise<string> {
95-
const command = "powershell";
96-
const args = [
97-
"-executionPolicy",
98-
"bypass",
99-
"(Get-WmiObject Win32_OperatingSystem).OSArchitecture",
100-
];
101-
return utils
102-
.execChildProcess(command, args, utils.extensionContext.extensionPath)
103-
.then((architecture) => {
104-
if (architecture) {
105-
const archArray: string[] = architecture.split(os.EOL);
106-
if (archArray.length > 2) {
107-
const arch: string = archArray[1].trim();
108-
if (arch.indexOf("64") >= 0) {
109-
return "x86_x64";
110-
} else if (arch.indexOf("32") >= 0) {
111-
return "x86";
112-
}
113-
}
114-
}
115-
return PlatformInformation.GetUnknownArchitecture();
116-
})
117-
.catch((err) => {
118-
return PlatformInformation.GetUnknownArchitecture();
119-
});
120-
}
12194
constructor(public platform: string, public architecture: string) {}
12295
}

src/espIdf/menuconfig/confServerProcess.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ export class ConfserverProcess {
226226
(idfConf.readParameter("idf.sdkconfigDefaults") as string[]) || [];
227227

228228
if (reconfigureArgs.indexOf("SDKCONFIG") === -1) {
229-
reconfigureArgs.push(`-DSDKCONFIG='${ConfserverProcess.instance.configFile}'`)
229+
reconfigureArgs.push(
230+
`-DSDKCONFIG='${ConfserverProcess.instance.configFile}'`
231+
);
230232
}
231233

232234
if (
@@ -261,7 +263,11 @@ export class ConfserverProcess {
261263
if (code !== 0) {
262264
const errorMsg = `When loading default values received exit signal: ${signal}, code : ${code}`;
263265
OutputChannel.appendLine(errorMsg, "SDK Configuration Editor");
264-
Logger.error(errorMsg, new Error(errorMsg), "ConfserverProcess setDefaultValues");
266+
Logger.error(
267+
errorMsg,
268+
new Error(errorMsg),
269+
"ConfserverProcess setDefaultValues"
270+
);
265271
}
266272
ConfserverProcess.init(currWorkspace, extensionPath);
267273
progress.report({ increment: 70, message: "The end" });
@@ -346,7 +352,7 @@ export class ConfserverProcess {
346352
(idfConf.readParameter("idf.sdkconfigDefaults") as string[]) || [];
347353

348354
if (confServerArgs.indexOf("SDKCONFIG") === -1) {
349-
confServerArgs.push(`-DSDKCONFIG='${this.configFile}'`)
355+
confServerArgs.push(`-DSDKCONFIG='${this.configFile}'`);
350356
}
351357

352358
if (
@@ -429,6 +435,7 @@ export class ConfserverProcess {
429435
"Saving config to",
430436
"Loading config from",
431437
"The following config symbol(s) were not visible so were not updated",
438+
"WARNING:",
432439
];
433440

434441
if (isStringNotEmpty(dataStr)) {
@@ -466,6 +473,10 @@ export class ConfserverProcess {
466473
OutputChannel.appendLine(
467474
"-----------------------END OF ERROR-----------------------"
468475
);
469-
Logger.error(data.toString(), new Error(data.toString()), "ConfserverProcess printError");
476+
Logger.error(
477+
data.toString(),
478+
new Error(data.toString()),
479+
"ConfserverProcess printError"
480+
);
470481
}
471482
}

src/espIdf/serial/serialPort.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,11 @@ export class SerialPort {
114114
OutputChannel.appendLine(
115115
`Detecting default port using esptool.py...`
116116
);
117-
const timeout = idfConf.readParameter(
118-
"idf.serialPortDetectionTimeout",
119-
workspaceFolder
120-
) as number * 1000; // Convert seconds to milliseconds
117+
const timeout =
118+
(idfConf.readParameter(
119+
"idf.serialPortDetectionTimeout",
120+
workspaceFolder
121+
) as number) * 1000; // Convert seconds to milliseconds
121122

122123
const result = await spawn(
123124
pythonBinPath,
@@ -126,6 +127,7 @@ export class SerialPort {
126127
silent: false,
127128
appendMode: "append",
128129
timeout: timeout,
130+
sendToTelemetry: false,
129131
}
130132
);
131133

@@ -309,7 +311,14 @@ export class SerialPort {
309311
const msg = error.message
310312
? error.message
311313
: "Something went wrong while getting the serial port list";
312-
Logger.errorNotify(msg, error, "SerialPort displayList");
314+
const sendToTelemetry = msg.indexOf("No serial ports found") === -1;
315+
Logger.errorNotify(
316+
msg,
317+
error,
318+
"SerialPort displayList",
319+
undefined,
320+
sendToTelemetry
321+
);
313322
OutputChannel.appendLine(msg, "Serial port");
314323
OutputChannel.appendLineAndShow(JSON.stringify(error));
315324
}
@@ -413,7 +422,12 @@ export class SerialPort {
413422
const chipIdBuffer = await spawn(
414423
pythonBinPath,
415424
[esptoolPath, "--port", serialPort.comName, "chip_id"],
416-
{ timeout: 2000, silent: true, appendMode: "append" }
425+
{
426+
timeout: 2000,
427+
silent: true,
428+
appendMode: "append",
429+
sendToTelemetry: false,
430+
}
417431
);
418432
const regexp = /Chip is(.*?)[\r]?\n/;
419433
const chipIdString = chipIdBuffer.toString().match(regexp);

src/idfComponentsDataProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ export class IdfTreeDataProvider implements TreeDataProvider<IdfComponent> {
121121
Logger.errorNotify(
122122
vscode.l10n.t("File project_description.json cannot be found."),
123123
new Error("File-Not-Found"),
124-
"IDFTreeDataProvider getComponentsInProject"
124+
"IDFTreeDataProvider getComponentsInProject",
125+
undefined,
126+
false
125127
);
126128
return null;
127129
}

src/idfToolsManager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export interface IEspIdfTool {
4040

4141
export class IdfToolsManager {
4242
public static async createIdfToolsManager(idfPath: string) {
43-
const platformInfo = await PlatformInformation.GetPlatformInformation();
43+
const platformInfo = PlatformInformation.GetPlatformInformation();
4444
const toolsJsonPath = await utils.getToolsJsonPath(idfPath);
4545
const toolsObj = await readJSON(toolsJsonPath);
4646
const idfToolsManager = new IdfToolsManager(
@@ -230,6 +230,10 @@ export class IdfToolsManager {
230230
const command = pkg.version_cmd[0];
231231
const args = pkg.version_cmd.slice(1);
232232
try {
233+
const isBinInPath = await utils.isBinInPath(command, modifiedEnv);
234+
if (!isBinInPath) {
235+
return "No match";
236+
}
233237
const binVersionResponse = await utils.execChildProcess(
234238
command,
235239
args,

src/logger/logger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export class Logger {
8282
errorStack: error.stack,
8383
category,
8484
capturedBy: "Logger",
85+
command: metadata?.command
8586
});
8687
}
8788
winston.log("error", message, {

src/setup/SetupPanel.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import {
5151
checkSpacesInPath,
5252
getEspIdfFromCMake,
5353
canAccessFile,
54-
execChildProcess,
5554
compareVersion,
5655
} from "../utils";
5756
import { useIdfSetupSettings } from "./setupValidation/espIdfSetup";

src/support/checkEspIdfTools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export async function checkEspIdfTools(
2727
reportedResult: reportObj,
2828
context: vscode.ExtensionContext
2929
) {
30-
const platformInfo = await PlatformInformation.GetPlatformInformation();
30+
const platformInfo = PlatformInformation.GetPlatformInformation();
3131
let toolsJsonPath: string = join(
3232
reportedResult.configurationSettings.espIdfPath,
3333
"tools",

src/test/suite/PlatformInformation.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ suite("PlatformInformation Tests", () => {
2828
extensionPath: __dirname,
2929
} as vscode.ExtensionContext;
3030
utils.setExtensionContext(mockUpContext); // Need a path to execute a child process to get info
31-
return PlatformInformation.GetPlatformInformation().then((actual) => {
32-
assert.equal(actual.platform, os.platform());
33-
assert.equal(actual.architecture, "x86_64");
34-
});
31+
const actual = PlatformInformation.GetPlatformInformation();
32+
assert.equal(actual.platform, os.platform());
33+
assert.equal(actual.architecture, "x64");
3534
});
3635
});

src/utils.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ export class PreCheck {
7575
Logger.errorNotify(
7676
preCheck[1],
7777
new Error("PRECHECK_FAILED"),
78-
"utils precheck failed"
78+
"utils precheck failed",
79+
undefined,
80+
false
7981
);
8082
}
8183
});
@@ -168,6 +170,8 @@ export interface ISpawnOptions extends childProcess.SpawnOptions {
168170
outputString?: string;
169171
/** Output append mode: 'appendLine', 'append', or undefined */
170172
appendMode?: "appendLine" | "append";
173+
/** Send error to telemetry */
174+
sendToTelemetry?: boolean;
171175
}
172176

173177
export function spawn(
@@ -177,10 +181,11 @@ export function spawn(
177181
outputString: "",
178182
silent: false,
179183
appendMode: "appendLine",
184+
sendToTelemetry: true,
180185
}
181186
): Promise<Buffer> {
182187
let buff = Buffer.alloc(0);
183-
const sendToOutputChannel = (data: Buffer) => {
188+
const sendToOutputChannel = (data: any) => {
184189
buff = Buffer.concat([buff, data]);
185190
options.outputString += buff.toString();
186191
if (!options.silent) {
@@ -225,7 +230,13 @@ export function spawn(
225230
resolve(buff);
226231
} else {
227232
const err = new Error("non zero exit code " + code + EOL + EOL + buff);
228-
Logger.error(err.message, err, "src utils spawn", { command });
233+
Logger.error(
234+
err.message,
235+
err,
236+
"src utils spawn",
237+
{ command },
238+
options.sendToTelemetry
239+
);
229240
reject(err);
230241
}
231242
});
@@ -665,7 +676,10 @@ export function execChildProcess(
665676
return reject(error);
666677
}
667678
if (stderr && stderr.length > 2) {
668-
if (!stderr.startsWith("Open On-Chip Debugger v")) {
679+
if (
680+
!stderr.startsWith("Open On-Chip Debugger v") &&
681+
!stderr.toLowerCase().startsWith("warning")
682+
) {
669683
Logger.error(
670684
stderr,
671685
new Error(stderr),
@@ -996,7 +1010,7 @@ export function validateFileSizeAndChecksum(
9961010
const fileSize = fs.statSync(filePath).size;
9971011
const readStream = fs.createReadStream(filePath);
9981012
let fileChecksum: string;
999-
readStream.on("data", (data) => {
1013+
readStream.on("data", (data: crypto.BinaryLike) => {
10001014
shashum.update(data);
10011015
});
10021016
readStream.on("end", () => {

0 commit comments

Comments
 (0)