Skip to content

Commit ebd03db

Browse files
PeterWonedooriya
authored andcommitted
Windows codepage bugfix (microsoft#899)
* Windows codepage bugfix * Escape backslash in literal string * Grooming to pacify Travis
1 parent 54d4ea9 commit ebd03db

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/arduino/arduino.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class ArduinoApp {
133133
const prebuildargs = dc.prebuild.split(" ");
134134
const prebuildCommand = prebuildargs.shift();
135135
try {
136-
await util.spawn(prebuildCommand, arduinoChannel.channel, prebuildargs, {shell: true, cwd: ArduinoWorkspace.rootPath});
136+
await util.spawn(prebuildCommand, arduinoChannel.channel, prebuildargs, { shell: true, cwd: ArduinoWorkspace.rootPath });
137137
} catch (ex) {
138138
arduinoChannel.error(`Run prebuild failed: \n${ex.error}`);
139139
return;
@@ -215,7 +215,7 @@ export class ArduinoApp {
215215

216216
const appPath = path.join(ArduinoWorkspace.rootPath, dc.sketch);
217217
const args = ["--upload", "--board", boardDescriptor, "--port", dc.port, "--useprogrammer",
218-
"--pref", "programmer=" + selectProgrammer, appPath];
218+
"--pref", "programmer=" + selectProgrammer, appPath];
219219
if (VscodeSettings.getInstance().logLevel === "verbose") {
220220
args.push("--verbose");
221221
}
@@ -269,7 +269,7 @@ export class ArduinoApp {
269269
const prebuildargs = dc.prebuild.split(" ");
270270
const prebuildCommand = prebuildargs.shift();
271271
try {
272-
await util.spawn(prebuildCommand, arduinoChannel.channel, prebuildargs, {shell: true, cwd: ArduinoWorkspace.rootPath});
272+
await util.spawn(prebuildCommand, arduinoChannel.channel, prebuildargs, { shell: true, cwd: ArduinoWorkspace.rootPath });
273273
} catch (ex) {
274274
arduinoChannel.error(`Run prebuild failed: \n${ex.error}`);
275275
return;
@@ -303,7 +303,12 @@ export class ArduinoApp {
303303
arduinoChannel.end(`Finished verify sketch - ${dc.sketch}${os.EOL}`);
304304
return true;
305305
} catch (reason) {
306-
arduinoChannel.error(`Exit with code=${reason.code}${os.EOL}`);
306+
const msg = reason.code ?
307+
`Exit with code=${reason.code}${os.EOL}` :
308+
reason.message ?
309+
reason.message :
310+
JSON.stringify(reason);
311+
arduinoChannel.error(msg);
307312
return false;
308313
}
309314

@@ -315,7 +320,7 @@ export class ArduinoApp {
315320
return;
316321
}
317322
const cppConfigFile = fs.readFileSync(configFilePath, "utf8");
318-
const cppConfig = JSON.parse(cppConfigFile) as {configurations: Array<{includePath: string[], forcedInclude: string[]}>};
323+
const cppConfig = JSON.parse(cppConfigFile) as { configurations: Array<{ includePath: string[], forcedInclude: string[] }> };
319324
const libPaths = this.getDefaultPackageLibPaths();
320325
const defaultForcedInclude = this.getDefaultForcedIncludeFiles();
321326
const configuration = cppConfig.configurations[0];

src/common/util.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as path from "path";
99
import * as properties from "properties";
1010
import * as vscode from "vscode";
1111
import * as WinReg from "winreg";
12+
import { arduinoChannel } from "./outputChannel";
1213

1314
const encodingMapping: object = JSON.parse(fs.readFileSync(path.join(__dirname, "../../../misc", "codepageMapping.json"), "utf8"));
1415

@@ -208,7 +209,14 @@ export function spawn(command: string, outputChannel: vscode.OutputChannel, args
208209

209210
let codepage = "65001";
210211
if (os.platform() === "win32") {
211-
codepage = childProcess.execSync("chcp").toString().split(":").pop().trim();
212+
try {
213+
const chcp = childProcess.execSync("chcp");
214+
codepage = chcp.toString().split(":").pop().trim();
215+
} catch (error) {
216+
arduinoChannel.warning(`Defaulting to code page 850 because chcp failed.\
217+
\rEnsure your path includes %SystemRoot%\\system32\r${error.message}`);
218+
codepage = "850";
219+
}
212220
}
213221

214222
if (outputChannel) {

0 commit comments

Comments
 (0)