@zuplo/cli 6.17.13 → 6.17.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,7 +9,7 @@ export interface ConsoleLogEntry {
|
|
|
9
9
|
loggingId: string;
|
|
10
10
|
buildId: string;
|
|
11
11
|
rayId: string | null;
|
|
12
|
-
messages:
|
|
12
|
+
messages: string[];
|
|
13
13
|
requestId: string;
|
|
14
14
|
vectorClock: number;
|
|
15
15
|
url: string;
|
|
@@ -17,7 +17,8 @@ export interface ConsoleLogEntry {
|
|
|
17
17
|
method: string;
|
|
18
18
|
}
|
|
19
19
|
export declare function handleRuntimeStdio(stdout: Readable, stderr: Readable): void;
|
|
20
|
-
export declare function logConsole(level: LogLevel, data:
|
|
21
|
-
export declare function
|
|
20
|
+
export declare function logConsole(level: LogLevel, data: string, callDepth?: number): void;
|
|
21
|
+
export declare function logConsoleAsync(level: LogLevel, data: string, callDepth?: number): Promise<void>;
|
|
22
|
+
export declare function logStructured(logEntry: ConsoleLogEntry, message: string): Promise<void>;
|
|
22
23
|
export {};
|
|
23
24
|
//# sourceMappingURL=worker-output.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-output.d.ts","sourceRoot":"","sources":["../../src/common/worker-output.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAKvC,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAKpD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"worker-output.d.ts","sourceRoot":"","sources":["../../src/common/worker-output.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAKvC,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAKpD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,QAkIpE;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,SAAI,QAEtE;AAKD,wBAAsB,eAAe,CACnC,KAAK,EAAE,QAAQ,EACf,IAAI,EAAE,MAAM,EACZ,SAAS,SAAI,iBAsDd;AAGD,wBAAsB,aAAa,CACjC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,MAAM,iBAqBhB"}
|
|
@@ -70,44 +70,50 @@ export function handleRuntimeStdio(stdout, stderr) {
|
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
export function logConsole(level, data) {
|
|
74
|
-
void (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
73
|
+
export function logConsole(level, data, callDepth = 0) {
|
|
74
|
+
void logConsoleAsync(level, data, callDepth);
|
|
75
|
+
}
|
|
76
|
+
export async function logConsoleAsync(level, data, callDepth = 0) {
|
|
77
|
+
try {
|
|
78
|
+
if (!data) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (typeof data !== "string") {
|
|
82
|
+
console[level](data);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
let message = data?.trim();
|
|
86
|
+
if (!message || message?.length === 0) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (message.startsWith(`{`) && message.endsWith(`}`)) {
|
|
90
|
+
let logEntry;
|
|
91
|
+
try {
|
|
92
|
+
logEntry = JSON.parse(message);
|
|
86
93
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
logEntry = JSON.parse(message);
|
|
91
|
-
}
|
|
92
|
-
catch (e) {
|
|
94
|
+
catch (e) {
|
|
95
|
+
if (callDepth === 1) {
|
|
93
96
|
const lines = message.split("\n");
|
|
94
|
-
lines.
|
|
97
|
+
await Promise.all(lines.map(async (line) => logConsole(level, line, callDepth++)));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
console[level](data);
|
|
95
102
|
return;
|
|
96
103
|
}
|
|
97
|
-
const messages = logEntry.messages;
|
|
98
|
-
messages.forEach((msg) => void logStructured(logEntry, msg));
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
message = await formatMessage(message);
|
|
102
|
-
const line = `${getTimestamp()} ${levelFormats[level]} ${message}`;
|
|
103
|
-
console[level](line);
|
|
104
104
|
}
|
|
105
|
+
await Promise.all(logEntry.messages.map((msg) => logStructured(logEntry, msg)));
|
|
105
106
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
else {
|
|
108
|
+
message = await formatMessage(message);
|
|
109
|
+
const line = `${getTimestamp()} ${levelFormats[level]} ${message}`;
|
|
110
|
+
console[level](line);
|
|
109
111
|
}
|
|
110
|
-
}
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
const line = `${getTimestamp()} ${levelFormats[level]} ${JSON.stringify(data)}`;
|
|
115
|
+
console[level](line);
|
|
116
|
+
}
|
|
111
117
|
}
|
|
112
118
|
export async function logStructured(logEntry, message) {
|
|
113
119
|
if (typeof message === "object" &&
|
|
@@ -151,14 +157,34 @@ function getTimestamp(timestamp) {
|
|
|
151
157
|
return chalk.white(chalk.dim(`[${getTimeFormatter().format(timestamp ? new Date(timestamp) : new Date())}]`));
|
|
152
158
|
}
|
|
153
159
|
async function formatMessage(message) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
160
|
+
const trimmed = message.trim();
|
|
161
|
+
if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
|
|
162
|
+
try {
|
|
163
|
+
const data = JSON.parse(trimmed);
|
|
164
|
+
if ("stack" in data && isJavaScriptStackTrace(data.stack)) {
|
|
165
|
+
const { stack, message, name, ...err } = data;
|
|
166
|
+
const formatted = await formatError(stack);
|
|
167
|
+
let line;
|
|
168
|
+
if (name && message) {
|
|
169
|
+
line = `${name}: ${message}`;
|
|
170
|
+
}
|
|
171
|
+
else if (message) {
|
|
172
|
+
line = `Error: ${message}`;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
line = "An error occurred";
|
|
176
|
+
}
|
|
177
|
+
if (Object.keys(err).length > 0) {
|
|
178
|
+
line += "\n";
|
|
179
|
+
line += JSON.stringify(err);
|
|
180
|
+
}
|
|
181
|
+
return `${line}\n${formatted}`;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
}
|
|
158
186
|
}
|
|
159
|
-
return
|
|
160
|
-
? JSON.stringify(message)
|
|
161
|
-
: String(message);
|
|
187
|
+
return message;
|
|
162
188
|
}
|
|
163
189
|
async function formatError(error) {
|
|
164
190
|
const stack = await new StackTracey(error).cleanAsync();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-output.js","sourceRoot":"","sources":["../../src/common/worker-output.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,WAAW,MAAM,wBAAwB,CAAC;AACjD,OAAO,WAAW,MAAM,4BAA4B,CAAC;AACrD,OAAO,KAAK,MAAM,mBAAmB,CAAC;AAwBtC,MAAM,UAAU,kBAAkB,CAAC,MAAgB,EAAE,MAAgB;IAKnE,MAAM,WAAW,GAAG;QAElB,MAAM,CAAC,KAAa;YAClB,MAAM,6BAA6B,GAAG,KAAK,CAAC,QAAQ,CAClD,kEAAkE,CACnE,CAAC;YACF,MAAM,mCAAmC,GAAG,KAAK,CAAC,QAAQ,CACxD,6BAA6B,CAC9B,CAAC;YAIF,MAAM,gBAAgB,GAAG,8BAA8B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAEpE,OAAO,CACL,6BAA6B;gBAC7B,mCAAmC;gBACnC,gBAAgB,CACjB,CAAC;QACJ,CAAC;QAED,cAAc,CAAC,KAAa;YAC1B,OAAO,KAAK,CAAC,QAAQ,CAAC,uCAAuC,CAAC,CAAC;QACjE,CAAC;QACD,SAAS,CAAC,KAAa;YACrB,OAAO,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7C,CAAC;QACD,kBAAkB,CAAC,KAAa;YAC9B,OAAO,mCAAmC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzD,CAAC;QACD,iBAAiB,CAAC,KAAa;YAC7B,OAAO,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;QAC7C,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAsB,EAAE,EAAE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W,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,CAAC;IAExD,MAAM,YAAY,GAAG,MAAM,IAAI,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;IAEzD,MAAM,OAAO,GAAG;QAEd,gBAAgB,EAAE,KAAK;QAEvB,SAAS,EAAE,IAAI;QAGf,MAAM,EAAE,GAAG;QAGX,cAAc,EAAE,KAAK;QAGrB,WAAW,EAAE,IAAI;QAGjB,oBAAoB,EAAE,IAAI;QAG1B,cAAc,EAAE,CAAC;KAClB,CAAC;IAEF,OAAO,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,sBAAsB,CAAC,GAAW;IACzC,MAAM,eAAe,GACnB,2DAA2D,CAAC;IAC9D,OAAO,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC","sourcesContent":["/* eslint-disable no-console */\nimport chalk from \"chalk\";\nimport { Readable } from \"node:stream\";\nimport StackTracey from \"./errors/stacktracy.js\";\nimport forTerminal from \"./errors/youch-terminal.js\";\nimport Youch from \"./errors/youch.js\";\n\ntype LogLevel = \"error\" | \"warn\" | \"info\" | \"debug\";\n\n/**\n * This is the structure of the runtime console log transport log entry\n */\nexport interface ConsoleLogEntry {\n logId: string;\n logOwner: string;\n logSource: string;\n level: LogLevel;\n timestamp: string;\n loggingId: string;\n buildId: string;\n rayId: string | null;\n messages: unknown[];\n requestId: string;\n vectorClock: number;\n url: string;\n route: string;\n method: string;\n}\n\nexport function handleRuntimeStdio(stdout: Readable, stderr: Readable) {\n // ASSUMPTION: each chunk is a whole message from workerd\n // This may not hold across OSes/architectures, but it seems to work on macOS M-line\n // I'm going with this simple approach to avoid complicating this too early\n // We can iterate on this heuristic in the future if it causes issues\n const classifiers = {\n // Is this chunk a big chonky barf from workerd that we want to hijack to cleanup/ignore?\n isBarf(chunk: string) {\n const containsLlvmSymbolizerWarning = chunk.includes(\n \"Not symbolizing stack traces because $LLVM_SYMBOLIZER is not set\"\n );\n const containsRecursiveIsolateLockWarning = chunk.includes(\n \"took recursive isolate lock\"\n );\n // Matches stack traces from workerd\n // - on unix: groups of 9 hex digits separated by spaces\n // - on windows: groups of 12 hex digits, or a single digit 0, separated by spaces\n const containsHexStack = /stack:( (0|[a-f\\d]{4,})){3,}/.test(chunk);\n\n return (\n containsLlvmSymbolizerWarning ||\n containsRecursiveIsolateLockWarning ||\n containsHexStack\n );\n },\n // Is this chunk an Address In Use error?\n isAddressInUse(chunk: string) {\n return chunk.includes(\"Address already in use; toString() = \");\n },\n isWarning(chunk: string) {\n return /\\.c\\+\\+:\\d+: warning:/.test(chunk);\n },\n isCodeMovedWarning(chunk: string) {\n return /CODE_MOVED for unknown code block/.test(chunk);\n },\n isAccessViolation(chunk: string) {\n return chunk.includes(\"access violation;\");\n },\n };\n\n stdout.on(\"data\", (chunk: Buffer | string) => {\n chunk = chunk.toString().trim();\n\n if (classifiers.isBarf(chunk)) {\n // this is a big chonky barf from workerd that we want to hijack to cleanup/ignore\n\n // CLEANABLE:\n // there are no known cases to cleanup yet\n // but, as they are identified, we will do that here\n\n // IGNORABLE:\n // anything else not handled above is considered ignorable\n // so send it to the debug logs which are discarded unless\n // the user explicitly sets a logLevel indicating they care\n logConsole(\"debug\", chunk);\n }\n\n // known case: warnings are not info, log them as such\n else if (classifiers.isWarning(chunk)) {\n logConsole(\"warn\", chunk);\n }\n\n // anything not explicitly handled above should be logged as info (via stdout)\n else {\n //logger.info(getSourceMappedString(chunk));\n logConsole(\"error\", chunk);\n }\n });\n\n stderr.on(\"data\", (chunk: Buffer | string) => {\n chunk = chunk.toString().trim();\n\n if (classifiers.isBarf(chunk)) {\n // this is a big chonky barf from workerd that we want to hijack to cleanup/ignore\n\n // CLEANABLE:\n // known case to cleanup: Address in use errors\n if (classifiers.isAddressInUse(chunk)) {\n const address = chunk.match(\n /Address already in use; toString\\(\\) = (.+)\\n/\n )?.[1];\n\n logConsole(\n \"error\",\n `Address already in use (${address}). Please check that you are not already running a server on this address or specify a different port with --port.`\n );\n\n // Log the original error to the debug logs.\n logConsole(\"debug\", chunk);\n }\n // In the past we have seen Access Violation errors on Windows, which may be caused by an outdated\n // version of the Windows OS or the Microsoft Visual C++ Redistributable.\n // See https://github.com/cloudflare/workers-sdk/issues/6170#issuecomment-2245209918\n else if (classifiers.isAccessViolation(chunk)) {\n let error = \"There was an access violation in the runtime.\";\n if (process.platform === \"win32\") {\n error +=\n \"\\nOn Windows, this may be caused by an outdated Microsoft Visual C++ Redistributable library.\\n\" +\n \"Check that you have the latest version installed.\\n\" +\n \"See https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist.\";\n }\n logConsole(\"error\", error);\n\n // Log the original error to the debug logs.\n logConsole(\"debug\", chunk);\n }\n\n // IGNORABLE:\n // anything else not handled above is considered ignorable\n // so send it to the debug logs which are discarded unless\n // the user explicitly sets a logLevel indicating they care\n else {\n logConsole(\"debug\", chunk);\n }\n }\n\n // known case: warnings are not errors, log them as such\n else if (classifiers.isWarning(chunk)) {\n logConsole(\"warn\", chunk);\n }\n\n // known case: \"error: CODE_MOVED for unknown code block?\", warning for workerd devs, not application devs\n else if (classifiers.isCodeMovedWarning(chunk)) {\n // ignore entirely, don't even send it to the debug log file\n }\n\n // anything not explicitly handled above should be logged as an error (via stderr)\n else {\n //logConsole(\"error\", getSourceMappedString(chunk));\n logConsole(\"error\", chunk);\n }\n });\n}\n\n/**\n * This is what is logged when the runtime calls console.log, etc.\n */\nexport function logConsole(level: LogLevel, data: unknown) {\n void (async () => {\n try {\n if (!data) {\n return;\n }\n\n // This shouldn't happen, but just in case\n if (typeof data !== \"string\") {\n console[level](data);\n return;\n }\n\n let message = data?.trim();\n if (!message || message?.length === 0) {\n return;\n }\n\n if (message.startsWith(`{\"logId\":\"`)) {\n let logEntry: ConsoleLogEntry;\n try {\n logEntry = JSON.parse(message);\n } catch (e) {\n // We might have multiple log entries in a single chunk\n // so split them and log each one\n const lines = message.split(\"\\n\");\n lines.forEach((line) => void logConsole(level, line));\n return;\n }\n const messages = logEntry.messages;\n messages.forEach((msg) => void logStructured(logEntry, msg));\n } else {\n message = await formatMessage(message);\n\n const line = `${getTimestamp()} ${levelFormats[level]} ${message}`;\n\n console[level](line);\n }\n } catch (err) {\n console.log(err);\n console[level](data);\n }\n })();\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport async function logStructured(\n logEntry: ConsoleLogEntry,\n message: unknown\n) {\n if (\n typeof message === \"object\" &&\n message &&\n Object.keys(message).length === 0\n ) {\n return;\n }\n\n // Get the log properties we care about\n const { level, route, method, timestamp } = logEntry;\n\n const routeStr = route.endsWith(\"{/}?\") ? route.slice(0, -4) : route;\n\n const msg = await formatMessage(message);\n\n const line = `${getTimestamp(timestamp)} ${levelFormats[level]} [${methodFormats[method.toUpperCase() as HttpMethod]} ${chalk.blue(routeStr)}] ${msg}`;\n\n // Log the line\n console[level](line);\n}\n\ntype HttpMethod =\n | \"GET\"\n | \"POST\"\n | \"PUT\"\n | \"DELETE\"\n | \"PATCH\"\n | \"HEAD\"\n | \"OPTIONS\";\nconst methodFormats: Record<HttpMethod, string> = {\n GET: chalk.green(chalk.bold(\"GET\")),\n POST: chalk.blue(chalk.bold(\"POST\")),\n PUT: chalk.yellow(chalk.bold(\"PUT\")),\n DELETE: chalk.red(chalk.bold(\"DELETE\")),\n PATCH: chalk.magenta(chalk.bold(\"PATCH\")),\n HEAD: chalk.cyan(chalk.bold(\"HEAD\")),\n OPTIONS: chalk.gray(chalk.bold(\"OPTIONS\")),\n};\n\nconst levelFormats: Record<LogLevel, string> = {\n error: chalk.red(chalk.bold(\"ERROR\".padEnd(5))),\n warn: chalk.yellow(chalk.bold(\"WARN\".padEnd(5))),\n info: chalk.blue(chalk.bold(\"INFO\".padEnd(5))),\n debug: chalk.gray(chalk.bold(\"DEBUG\".padEnd(5))),\n};\n\n// Only initialize the timeFormatter when the timestamp option is used, and\n// reuse it across all loggers\nlet timeFormatter: Intl.DateTimeFormat;\nfunction getTimeFormatter() {\n timeFormatter ??= new Intl.DateTimeFormat(undefined, {\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n hour12: false,\n fractionalSecondDigits: 3,\n });\n return timeFormatter;\n}\n\nfunction getTimestamp(timestamp?: string) {\n return chalk.white(\n chalk.dim(\n `[${getTimeFormatter().format(timestamp ? new Date(timestamp) : new Date())}]`\n )\n );\n}\n\nasync function formatMessage(message: unknown): Promise<string> {\n if (typeof message === \"string\" && isJavaScriptStackTrace(message)) {\n const lines = message.split(\"\\n\");\n const title = lines.shift();\n return title + \"\\n\" + (await formatError(lines.join(\"\\n\")));\n }\n\n return typeof message === \"object\"\n ? JSON.stringify(message)\n : String(message);\n}\n\nasync function formatError(error: string) {\n const stack = await new StackTracey(error).cleanAsync();\n\n const jsonResponse = await new Youch(stack, {}).toJSON();\n\n const options = {\n // Defaults to false\n displayShortPath: false,\n\n fileShort: true,\n\n // Defaults to single whitspace\n prefix: \" \",\n\n // Defaults to false\n hideErrorTitle: false,\n\n // Defaults to false\n hideMessage: true,\n\n // Defaults to false\n displayMainFrameOnly: true,\n\n // Defaults to 3\n framesMaxLimit: 3,\n };\n\n return forTerminal(jsonResponse, options);\n}\n\nfunction isJavaScriptStackTrace(str: string): boolean {\n const stackTraceRegex =\n /at\\s+(.*?)\\s+\\((.*?):(\\d+):(\\d+)\\)|at\\s+(.*?):(\\d+):(\\d+)/;\n return stackTraceRegex.test(str);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-output.js","sourceRoot":"","sources":["../../src/common/worker-output.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,WAAW,MAAM,wBAAwB,CAAC;AACjD,OAAO,WAAW,MAAM,4BAA4B,CAAC;AACrD,OAAO,KAAK,MAAM,mBAAmB,CAAC;AAwBtC,MAAM,UAAU,kBAAkB,CAAC,MAAgB,EAAE,MAAgB;IAKnE,MAAM,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:stream\";\nimport StackTracey from \"./errors/stacktracy.js\";\nimport forTerminal from \"./errors/youch-terminal.js\";\nimport Youch from \"./errors/youch.js\";\n\ntype LogLevel = \"error\" | \"warn\" | \"info\" | \"debug\";\n\n/**\n * This is the structure of the runtime console log transport log entry\n */\nexport interface ConsoleLogEntry {\n logId: string;\n logOwner: string;\n logSource: string;\n level: LogLevel;\n timestamp: string;\n loggingId: string;\n buildId: string;\n rayId: string | null;\n messages: string[];\n requestId: string;\n vectorClock: number;\n url: string;\n route: string;\n method: string;\n}\n\nexport function handleRuntimeStdio(stdout: Readable, stderr: Readable) {\n // ASSUMPTION: each chunk is a whole message from workerd\n // This may not hold across OSes/architectures, but it seems to work on macOS M-line\n // I'm going with this simple approach to avoid complicating this too early\n // We can iterate on this heuristic in the future if it causes issues\n const classifiers = {\n // Is this chunk a big chonky barf from workerd that we want to hijack to cleanup/ignore?\n isBarf(chunk: string) {\n const containsLlvmSymbolizerWarning = chunk.includes(\n \"Not symbolizing stack traces because $LLVM_SYMBOLIZER is not set\"\n );\n const containsRecursiveIsolateLockWarning = chunk.includes(\n \"took recursive isolate lock\"\n );\n // Matches stack traces from workerd\n // - on unix: groups of 9 hex digits separated by spaces\n // - on windows: groups of 12 hex digits, or a single digit 0, separated by spaces\n const containsHexStack = /stack:( (0|[a-f\\d]{4,})){3,}/.test(chunk);\n\n return (\n containsLlvmSymbolizerWarning ||\n containsRecursiveIsolateLockWarning ||\n containsHexStack\n );\n },\n // Is this chunk an Address In Use error?\n isAddressInUse(chunk: string) {\n return chunk.includes(\"Address already in use; toString() = \");\n },\n isWarning(chunk: string) {\n return /\\.c\\+\\+:\\d+: warning:/.test(chunk);\n },\n isCodeMovedWarning(chunk: string) {\n return /CODE_MOVED for unknown code block/.test(chunk);\n },\n isAccessViolation(chunk: string) {\n return chunk.includes(\"access violation;\");\n },\n };\n\n stdout.on(\"data\", (chunk: Buffer | string) => {\n chunk = chunk.toString().trim();\n\n if (classifiers.isBarf(chunk)) {\n // this is a big chonky barf from workerd that we want to hijack to cleanup/ignore\n\n // CLEANABLE:\n // there are no known cases to cleanup yet\n // but, as they are identified, we will do that here\n\n // IGNORABLE:\n // anything else not handled above is considered ignorable\n // so send it to the debug logs which are discarded unless\n // the user explicitly sets a logLevel indicating they care\n logConsole(\"debug\", chunk);\n }\n\n // known case: warnings are not info, log them as such\n else if (classifiers.isWarning(chunk)) {\n logConsole(\"warn\", chunk);\n }\n\n // anything not explicitly handled above should be logged as info (via stdout)\n else {\n logConsole(\"error\", chunk);\n }\n });\n\n stderr.on(\"data\", (chunk: Buffer | string) => {\n chunk = chunk.toString().trim();\n\n if (classifiers.isBarf(chunk)) {\n // this is a big chonky barf from workerd that we want to hijack to cleanup/ignore\n\n // CLEANABLE:\n // known case to cleanup: Address in use errors\n if (classifiers.isAddressInUse(chunk)) {\n const address = chunk.match(\n /Address already in use; toString\\(\\) = (.+)\\n/\n )?.[1];\n\n logConsole(\n \"error\",\n `Address already in use (${address}). Please check that you are not already running a server on this address or specify a different port with --port.`\n );\n\n // Log the original error to the debug logs.\n logConsole(\"debug\", chunk);\n }\n // In the past we have seen Access Violation errors on Windows, which may be caused by an outdated\n // version of the Windows OS or the Microsoft Visual C++ Redistributable.\n // See https://github.com/cloudflare/workers-sdk/issues/6170#issuecomment-2245209918\n else if (classifiers.isAccessViolation(chunk)) {\n let error = \"There was an access violation in the runtime.\";\n if (process.platform === \"win32\") {\n error +=\n \"\\nOn Windows, this may be caused by an outdated Microsoft Visual C++ Redistributable library.\\n\" +\n \"Check that you have the latest version installed.\\n\" +\n \"See https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist.\";\n }\n logConsole(\"error\", error);\n\n // Log the original error to the debug logs.\n logConsole(\"debug\", chunk);\n }\n\n // IGNORABLE:\n // anything else not handled above is considered ignorable\n // so send it to the debug logs which are discarded unless\n // the user explicitly sets a logLevel indicating they care\n else {\n logConsole(\"debug\", chunk);\n }\n }\n\n // known case: warnings are not errors, log them as such\n else if (classifiers.isWarning(chunk)) {\n logConsole(\"warn\", chunk);\n }\n\n // known case: \"error: CODE_MOVED for unknown code block?\", warning for workerd devs, not application devs\n else if (classifiers.isCodeMovedWarning(chunk)) {\n // ignore entirely, don't even send it to the debug log file\n }\n\n // anything not explicitly handled above should be logged as an error (via stderr)\n else {\n logConsole(\"error\", chunk);\n }\n });\n}\n\nexport function logConsole(level: LogLevel, data: string, callDepth = 0) {\n void logConsoleAsync(level, data, callDepth);\n}\n\n/**\n * This is what is logged when the runtime calls console.log, etc.\n */\nexport async function logConsoleAsync(\n level: LogLevel,\n data: string,\n callDepth = 0\n) {\n try {\n if (!data) {\n return;\n }\n\n // This shouldn't happen, but just in case\n if (typeof data !== \"string\") {\n console[level](data);\n return;\n }\n\n let message = data?.trim();\n if (!message || message?.length === 0) {\n return;\n }\n\n // Probably a JSON object\n if (message.startsWith(`{`) && message.endsWith(`}`)) {\n let logEntry: ConsoleLogEntry;\n try {\n logEntry = JSON.parse(message);\n } catch (e) {\n // If we are at a depth of 1 it means we are trying to handle the case\n // where a chunk might be multiple JSON entries.\n if (callDepth === 1) {\n // We might have multiple log entries in a single chunk\n // so split them and log each one\n const lines = message.split(\"\\n\");\n await Promise.all(\n lines.map(async (line) => logConsole(level, line, callDepth++))\n );\n return;\n } else {\n console[level](data);\n return;\n }\n }\n await Promise.all(\n logEntry.messages.map((msg) => logStructured(logEntry, msg))\n );\n } else {\n message = await formatMessage(message);\n\n const line = `${getTimestamp()} ${levelFormats[level]} ${message}`;\n\n console[level](line);\n }\n } catch (err) {\n const line = `${getTimestamp()} ${levelFormats[level]} ${JSON.stringify(data)}`;\n\n console[level](line);\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport async function logStructured(\n logEntry: ConsoleLogEntry,\n message: string\n) {\n if (\n typeof message === \"object\" &&\n message &&\n Object.keys(message).length === 0\n ) {\n return;\n }\n\n // Get the log properties we care about\n const { level, route, method, timestamp } = logEntry;\n\n const routeStr = route.endsWith(\"{/}?\") ? route.slice(0, -4) : route;\n\n const msg = await formatMessage(message);\n\n const line = `${getTimestamp(timestamp)} ${levelFormats[level]} [${methodFormats[method.toUpperCase() as HttpMethod]} ${chalk.blue(routeStr)}] ${msg}`;\n\n // Log the line\n console[level](line);\n}\n\ntype HttpMethod =\n | \"GET\"\n | \"POST\"\n | \"PUT\"\n | \"DELETE\"\n | \"PATCH\"\n | \"HEAD\"\n | \"OPTIONS\";\nconst methodFormats: Record<HttpMethod, string> = {\n GET: chalk.green(chalk.bold(\"GET\")),\n POST: chalk.blue(chalk.bold(\"POST\")),\n PUT: chalk.yellow(chalk.bold(\"PUT\")),\n DELETE: chalk.red(chalk.bold(\"DELETE\")),\n PATCH: chalk.magenta(chalk.bold(\"PATCH\")),\n HEAD: chalk.cyan(chalk.bold(\"HEAD\")),\n OPTIONS: chalk.gray(chalk.bold(\"OPTIONS\")),\n};\n\nconst levelFormats: Record<LogLevel, string> = {\n error: chalk.red(chalk.bold(\"ERROR\".padEnd(5))),\n warn: chalk.yellow(chalk.bold(\"WARN\".padEnd(5))),\n info: chalk.blue(chalk.bold(\"INFO\".padEnd(5))),\n debug: chalk.gray(chalk.bold(\"DEBUG\".padEnd(5))),\n};\n\n// Only initialize the timeFormatter when the timestamp option is used, and\n// reuse it across all loggers\nlet timeFormatter: Intl.DateTimeFormat;\nfunction getTimeFormatter() {\n timeFormatter ??= new Intl.DateTimeFormat(undefined, {\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n hour12: false,\n fractionalSecondDigits: 3,\n });\n return timeFormatter;\n}\n\nfunction getTimestamp(timestamp?: string) {\n return chalk.white(\n chalk.dim(\n `[${getTimeFormatter().format(timestamp ? new Date(timestamp) : new Date())}]`\n )\n );\n}\n\nasync function formatMessage(message: string): Promise<string> {\n const trimmed = message.trim();\n if (trimmed.startsWith(\"{\") && trimmed.endsWith(\"}\")) {\n try {\n const data = JSON.parse(trimmed);\n if (\"stack\" in data && isJavaScriptStackTrace(data.stack)) {\n const { stack, message, name, ...err } = data;\n\n const formatted = await formatError(stack);\n let line: string;\n if (name && message) {\n line = `${name}: ${message}`;\n } else if (message) {\n line = `Error: ${message}`;\n } else {\n line = \"An error occurred\";\n }\n\n if (Object.keys(err).length > 0) {\n line += \"\\n\";\n line += JSON.stringify(err);\n }\n\n return `${line}\\n${formatted}`;\n }\n } catch (err) {\n // Ignore\n }\n }\n\n return message;\n}\n\nasync function formatError(error: string | Error) {\n const stack = await new StackTracey(error).cleanAsync();\n\n const jsonResponse = await new Youch(stack, {}).toJSON();\n\n const options = {\n // Defaults to false\n displayShortPath: false,\n\n fileShort: true,\n\n // Defaults to single whitspace\n prefix: \" \",\n\n // Defaults to false\n hideErrorTitle: false,\n\n // Defaults to false\n hideMessage: true,\n\n // Defaults to false\n displayMainFrameOnly: true,\n\n // Defaults to 3\n framesMaxLimit: 3,\n };\n\n return forTerminal(jsonResponse, options);\n}\n\nfunction isJavaScriptStackTrace(str: string): boolean {\n const stackTraceRegex =\n /at\\s+(.*?)\\s+\\((.*?):(\\d+):(\\d+)\\)|at\\s+(.*?):(\\d+):(\\d+)/;\n return stackTraceRegex.test(str);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuplo/cli",
|
|
3
|
-
"version": "6.17.
|
|
3
|
+
"version": "6.17.14",
|
|
4
4
|
"repository": "https://github.com/zuplo/zuplo",
|
|
5
5
|
"author": "Zuplo, Inc.",
|
|
6
6
|
"type": "module",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"@opentelemetry/api": "^1.8.0",
|
|
30
30
|
"@sentry/node": "^7.119.2",
|
|
31
31
|
"@swc/core": "1.7.22",
|
|
32
|
-
"@zuplo/core": "^6.17.
|
|
33
|
-
"@zuplo/runtime": "^6.17.
|
|
32
|
+
"@zuplo/core": "^6.17.14",
|
|
33
|
+
"@zuplo/runtime": "^6.17.14",
|
|
34
34
|
"as-table": "^1.0.55",
|
|
35
35
|
"chalk": "^5.3.0",
|
|
36
36
|
"chokidar": "^3.5.3",
|