MCPcopy
hub / github.com/microsoft/vscode / pipeLoggingToParent

Function pipeLoggingToParent

src/bootstrap-fork.ts:14–154  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12//#region Helpers
13
14function pipeLoggingToParent(): void {
15 const MAX_STREAM_BUFFER_LENGTH = 1024 * 1024;
16 const MAX_LENGTH = 100000;
17
18 /**
19 * Prevent circular stringify and convert arguments to real array
20 */
21 function safeToString(args: ArrayLike<unknown>): string {
22 const seen: unknown[] = [];
23 const argsArray: unknown[] = [];
24
25 // Massage some arguments with special treatment
26 if (args.length) {
27 for (let i = 0; i < args.length; i++) {
28 let arg = args[i];
29
30 // Any argument of type 'undefined' needs to be specially treated because
31 // JSON.stringify will simply ignore those. We replace them with the string
32 // 'undefined' which is not 100% right, but good enough to be logged to console
33 if (typeof arg === 'undefined') {
34 arg = 'undefined';
35 }
36
37 // Any argument that is an Error will be changed to be just the error stack/message
38 // itself because currently cannot serialize the error over entirely.
39 else if (arg instanceof Error) {
40 const errorObj = arg;
41 if (errorObj.stack) {
42 arg = errorObj.stack;
43 } else {
44 arg = errorObj.toString();
45 }
46 }
47
48 argsArray.push(arg);
49 }
50 }
51
52 try {
53 const res = JSON.stringify(argsArray, function (key, value: unknown) {
54
55 // Objects get special treatment to prevent circles
56 if (isObject(value) || Array.isArray(value)) {
57 if (seen.indexOf(value) !== -1) {
58 return '[Circular]';
59 }
60
61 seen.push(value);
62 }
63
64 return value;
65 });
66
67 if (res.length > MAX_LENGTH) {
68 return 'Output omitted for a large object that exceeds the limits';
69 }
70
71 return res;

Callers 1

bootstrap-fork.tsFile · 0.85

Calls 2

wrapConsoleMethodFunction · 0.85
wrapStreamFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…