Skip to content

Commit

Permalink
Improve logging for 'dotnet --info' failures (#159)
Browse files Browse the repository at this point in the history
Previously failures from dotnet --info generated no logging. This adds code to output what is happening.
  • Loading branch information
gregg-miskelly committed Apr 8, 2016
1 parent a2471e6 commit 01aa7b6
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 40 deletions.
81 changes: 75 additions & 6 deletions src/coreclr-debug/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function activate(context: vscode.ExtensionContext, reporter: TelemetryRe

writeInstallBeginFile().then(function() {
installStage = 'writeProjectJson';
return writeProjectJson();
return writeProjectJson(_channel);
}).then(function() {
installStage = 'dotnetRestore'
return spawnChildProcess('dotnet', ['--verbose', 'restore', '--configfile', 'NuGet.config'], _channel, _util.coreClrDebugDir())
Expand Down Expand Up @@ -240,12 +240,16 @@ function ensureAd7EngineExists(channel: vscode.OutputChannel, outputDirectory: s
});
}

function writeProjectJson(): Promise<void> {
return new Promise<void>(function(resolve, reject) {
var projectJson = createProjectJson(CoreClrDebugUtil.getPlatformRuntimeId());
function writeProjectJson(channel: vscode.OutputChannel): Promise<void> {
return new Promise<void>(function (resolve, reject) {
const projectJsonPath = path.join(_util.coreClrDebugDir(), 'project.json');
_channel.appendLine('Creating ' + projectJsonPath);

const projectJson = createProjectJson(getPlatformRuntimeId(channel));

fs.writeFile(path.join(_util.coreClrDebugDir(), 'project.json'), JSON.stringify(projectJson, null, 2), {encoding: 'utf8'}, function(err) {
if (err) {
fs.writeFile(projectJsonPath, JSON.stringify(projectJson, null, 2), {encoding: 'utf8'}, function(err) {
if (err) {
channel.appendLine('Error: Unable to write to project.json: ' + err.message);
reject(err.code);
}
else {
Expand All @@ -255,6 +259,71 @@ function writeProjectJson(): Promise<void> {
});
}

function getPlatformRuntimeId(channel: vscode.OutputChannel) : string {
switch (process.platform) {
case 'win32':
return 'win7-x64';
case 'darwin':
return getDotnetRuntimeId(channel);
case 'linux':
return getDotnetRuntimeId(channel);
default:
channel.appendLine('Error: Unsupported platform ' + process.platform);
throw Error('Unsupported platform ' + process.platform);
}
}

function getDotnetRuntimeId(channel: vscode.OutputChannel): string {
channel.appendLine("Starting 'dotnet --info'");

const cliVersionErrorMessage = "Ensure that .NET Core CLI Tools version >= 1.0.0-beta-002173 is installed. Run 'dotnet --version' to see what version is installed.";

let child = child_process.spawnSync('dotnet', ['--info'], { cwd: _util.coreClrDebugDir() });

if (child.stderr.length > 0) {
channel.append('Error: ' + child.stderr.toString());
}
const out = child.stdout.toString();
if (out.length > 0) {
channel.append(out);
}

if (child.status !== 0) {
const message = `Error: 'dotnet --info' failed with error ${child.status}`;
channel.appendLine(message);
channel.appendLine(cliVersionErrorMessage);
throw new Error(message);
}

if (out.length === 0) {
const message = "Error: 'dotnet --info' provided no output";
channel.appendLine(message);
channel.appendLine(cliVersionErrorMessage);
throw new Error(message);
}

let lines = out.split('\n');
let ridLine = lines.filter(function (value) {
return value.trim().startsWith('RID:');
});

if (ridLine.length < 1) {
channel.appendLine("Error: Cannot find 'RID' property");
channel.appendLine(cliVersionErrorMessage);
throw new Error('Cannot obtain Runtime ID from dotnet cli');
}

let rid = ridLine[0].split(':')[1].trim();

if (!rid) {
channel.appendLine("Error: Unable to parse 'RID' property.");
channel.appendLine(cliVersionErrorMessage);
throw new Error('Unable to determine Runtime ID');
}

return rid;
}

function createProjectJson(targetRuntime: string): any
{
let projectJson = {
Expand Down
34 changes: 0 additions & 34 deletions src/coreclr-debug/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,40 +112,6 @@ export default class CoreClrDebugUtil
}
}

static getPlatformRuntimeId() : string {
switch(process.platform) {
case 'win32':
return 'win7-x64';
case 'darwin':
return CoreClrDebugUtil.getDotnetRuntimeId();
case 'linux':
return CoreClrDebugUtil.getDotnetRuntimeId();
default:
throw Error('Unsupported platform ' + process.platform);
}
}

static getDotnetRuntimeId() : string {
let out = child_process.execSync('dotnet --info').toString();

let lines = out.split('\n');
let ridLine = lines.filter(function(value) {
return value.trim().startsWith('RID');
});

if (ridLine.length < 1) {
throw new Error('Cannot obtain Runtime ID from dotnet cli');
}

let rid = ridLine[0].split(':')[1].trim();

if (!rid) {
throw new Error('Unable to determine Runtime ID');
}

return rid;
}

/** Used for diagnostics only */
logToFile(message: string): void {
let logFolder = path.resolve(this.coreClrDebugDir(), "extension.log");
Expand Down

0 comments on commit 01aa7b6

Please sign in to comment.