azdata extension fix/updates (#12008)

This commit is contained in:
Charles Gagnon
2020-08-28 16:49:21 -07:00
committed by GitHub
parent 47c1204e89
commit e9b00062a4
3 changed files with 23 additions and 13 deletions

View File

@@ -128,11 +128,18 @@ export class AzdataTool implements IAzdataTool {
result: <R>output.result
};
} catch (err) {
// Since the output is JSON we need to do some extra parsing here to get the correct stderr out.
// The actual value we get is something like ERROR: { stderr: '...' } so we also need to trim
// off the start that isn't a valid JSON blob
if (err instanceof ExitCodeError) {
err.stderr = JSON.parse(err.stderr.substring(err.stderr.indexOf('{'))).stderr;
try {
// For azdata internal errors the output is JSON and so we need to do some extra parsing here
// to get the correct stderr out. The actual value we get is something like
// ERROR: { stderr: '...' }
// so we also need to trim off the start that isn't a valid JSON blob
err.stderr = JSON.parse(err.stderr.substring(err.stderr.indexOf('{'))).stderr;
} catch (err) {
// no op - it means this was probably some other generic error (such as command not being found)
}
}
throw err;
}
@@ -285,9 +292,8 @@ async function installAzdataLinux(): Promise<void> {
/**
*/
async function findSpecificAzdata(): Promise<IAzdataTool> {
const promise = ((process.platform === 'win32') ? searchForCmd('azdata.cmd') : searchForCmd('azdata'));
const path = `"${await promise}"`; // throws if azdata is not found
const versionOutput = await executeAzdataCommand(path, ['--version']);
const path = await ((process.platform === 'win32') ? searchForCmd('azdata.cmd') : searchForCmd('azdata'));
const versionOutput = await executeAzdataCommand(`"${path}"`, ['--version']);
return new AzdataTool(path, parseVersion(versionOutput.stdout));
}