Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Verify the program attribute passed to debugAdapter (#790)
Browse files Browse the repository at this point in the history
* Verify the program attribute passed to debugAdapter

The program attribute should point to a valid file or
directory for selected mode. This patch improves error
messages shown when program attribute is invalid.

* Fix linting errors
  • Loading branch information
Suraj Barkale authored and ramya-rao-a committed Feb 13, 2017
1 parent f05b910 commit 6ed16f4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as os from 'os';
import { DebugProtocol } from 'vscode-debugprotocol';
import { DebugSession, InitializedEvent, TerminatedEvent, ThreadEvent, StoppedEvent, OutputEvent, Thread, StackFrame, Scope, Source, Handles } from 'vscode-debugadapter';
import { readFileSync, existsSync, lstatSync } from 'fs';
import { basename, dirname } from 'path';
import { basename, dirname, extname } from 'path';
import { spawn, ChildProcess, execSync, spawnSync } from 'child_process';
import { Client, RPCConnection } from 'json-rpc2';
import { getBinPathWithPreferredGopath, resolvePath } from '../goPath';
Expand Down Expand Up @@ -232,10 +232,21 @@ class Delve {

let dlvCwd = dirname(program);
try {
if (lstatSync(program).isDirectory()) {
let pstats = lstatSync(program);
if (pstats.isDirectory()) {
if (mode === 'exec') {
logError(`The program "${program}" must not be a directory in exec mode`);
return reject('The program attribute must be an executable in exec mode');
}
dlvCwd = program;
} else if (mode !== 'exec' && extname(program) !== '.go') {
logError(`The program "${program}" must be a valid go file in debug mode`);
return reject('The program attribute must be a directory or .go file in debug mode');
}
} catch (e) { }
} catch (e) {
logError(`The program "${program}" does not exist: ${e}`);
return reject('The program attribute must point to valid directory, .go file or executable.');
}
this.debugProcess = spawn(dlv, dlvArgs, {
cwd: dlvCwd,
env: dlvEnv,
Expand Down

0 comments on commit 6ed16f4

Please sign in to comment.