mirror of
https://github.com/Microsoft/vscode
synced 2024-10-06 03:17:00 +00:00
support null, undefined and errors in extension output (fixes #9)
This commit is contained in:
parent
57a1b92b1b
commit
3605e5dba1
31
src/bootstrap.js
vendored
31
src/bootstrap.js
vendored
|
@ -10,11 +10,36 @@ if (!!process.send && process.env.PIPE_LOGGING === 'true') {
|
|||
var MAX_LENGTH = 100000;
|
||||
|
||||
// Prevent circular stringify
|
||||
function safeStringify(obj) {
|
||||
function safeStringify(args) {
|
||||
var seen = [];
|
||||
var res;
|
||||
|
||||
// Massage some arguments with special treatment
|
||||
if (args.length) {
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
|
||||
// Any argument of type 'undefined' needs to be specially treated because
|
||||
// JSON.stringify will simply ignore those. We replace them with the string
|
||||
// 'undefined' which is not 100% right, but good enough to be logged to console
|
||||
if (typeof args[i] === 'undefined') {
|
||||
args[i] = 'undefined';
|
||||
}
|
||||
|
||||
// Any argument that is an Error will be changed to be just the error stack/message
|
||||
// itself because currently cannot serialize the error over entirely.
|
||||
else if (args[i] instanceof Error) {
|
||||
var errorObj = args[i];
|
||||
if (errorObj.stack) {
|
||||
args[i] = errorObj.stack;
|
||||
} else {
|
||||
args[i] = errorObj.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
res = JSON.stringify(obj, function (key, value) {
|
||||
res = JSON.stringify(args, function (key, value) {
|
||||
|
||||
// Objects get special treatment to prevent circles
|
||||
if (value && Object.prototype.toString.call(value) === '[object Object]') {
|
||||
|
@ -46,7 +71,7 @@ if (!!process.send && process.env.PIPE_LOGGING === 'true') {
|
|||
console.log = function () { /* ignore */ };
|
||||
console.warn = function () { /* ignore */ };
|
||||
}
|
||||
|
||||
|
||||
console.error = function () { process.send({ type: '__$console', severity: 'error', arguments: safeStringify(arguments) }); };
|
||||
|
||||
// Let stdout, stderr and stdin be no-op streams. This prevents an issue where we would get an EBADF
|
||||
|
|
|
@ -52,8 +52,18 @@ export class ExtensionOutputHandler implements IWorkbenchContribution {
|
|||
for (let i = 0; i < args.length; i++) {
|
||||
let a = args[i];
|
||||
|
||||
// Undefined gets printed as 'undefined'
|
||||
if (typeof a === 'undefined') {
|
||||
simpleVals.push('undefined');
|
||||
}
|
||||
|
||||
// Null gets printed as 'null'
|
||||
else if (a === null) {
|
||||
simpleVals.push('null');
|
||||
}
|
||||
|
||||
// Objects & Arrays are special because we want to inspect them in the REPL
|
||||
if (types.isObject(a) || Array.isArray(a)) {
|
||||
else if (types.isObject(a) || Array.isArray(a)) {
|
||||
|
||||
// Flush any existing simple values logged
|
||||
if (simpleVals.length) {
|
||||
|
|
Loading…
Reference in a new issue