Skip to content

Commit 513c3ab

Browse files
committed
fix: Adds logging in case there are issues with wasm packs
1 parent bdb0cb1 commit 513c3ab

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

src/lib/lifecycle/chunk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const chunk: LifecycleExecutor = async (
8181

8282
await callbacks.onResult(pack, result);
8383
logger.debug(
84-
`[${requestId}] (${LIFECYCLE_ID}) pack ${pack.name} completed`
84+
`[${requestId}] (${LIFECYCLE_ID}) pack ${pack.name} completed (captured: ${Object.keys(result.capture ?? {}).length})`
8585
);
8686
} else {
8787
logger.debug(

src/lib/lifecycle/post.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const post: LifecycleExecutor = async (
5151

5252
await callbacks.onResult(pack, result);
5353
logger.debug(
54-
`[${requestId}] (${LIFECYCLE_ID}) pack ${pack.name} completed`
54+
`[${requestId}] (${LIFECYCLE_ID}) pack ${pack.name} completed (captured: ${Object.keys(result.capture ?? {}).length})`
5555
);
5656
} else {
5757
logger.debug(

src/lib/lifecycle/pre.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,17 @@ export const pre: LifecycleExecutor = async (
4141

4242
if (output) {
4343
const result = output?.json() as PluginOutput;
44+
logger.debug(
45+
`[${requestId}] (${LIFECYCLE_ID}) pack ${pack.name} DATA: ${JSON.stringify(result)}`
46+
);
4447

4548
if (result.context) {
4649
context[`${index}`] = result.context;
4750
}
4851

4952
await callbacks.onResult(pack, result);
5053
logger.debug(
51-
`[${requestId}] (${LIFECYCLE_ID}) pack ${pack.name} completed`
54+
`[${requestId}] (${LIFECYCLE_ID}) pack ${pack.name} completed (captured: ${Object.keys(result.capture ?? {}).length})`
5255
);
5356
} else {
5457
logger.debug(

src/lib/sandbox.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ export const run = async (
4141
logger.debug(`[${requestId}] making request`);
4242
const finalizedRequest = request.clone();
4343
finalizedRequest.headers.set("x-tskl-bypass", "1");
44-
const rawResponse = await fetch(finalizedRequest);
4544
await pre;
4645

46+
// resolve the pre hooks as late as possible
47+
const [rawResponse] = await Promise.all([fetch(finalizedRequest), pre]);
48+
4749
// GZIP headers are being handled by undici and must be stripped
4850
const newHeaders: Array<[string, string]> = [...rawResponse.headers.entries()]
4951
.map(([key, value]) => {

test/packs.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe("Loading packs", () => {
6060
});
6161

6262
const t = taskless("test", {
63-
// logLevel: "debug",
63+
logLevel: "debug",
6464
logging: true,
6565
log: {
6666
data: logData,
@@ -113,18 +113,18 @@ describe("Loading packs", () => {
113113
await t.flush();
114114

115115
const log = logs[0];
116-
// console.log(JSON.stringify(logs, null, 2));
116+
console.log(JSON.stringify(logs, null, 2));
117117

118118
expect(
119119
log.dimensions.some(
120-
(d) => d.name === "testpack/testPre" && d.value === "preTest"
120+
(d) => d.name === "testpack/testPre" && d.value === "test_pre_value"
121121
),
122122
"Logs pre test capture"
123123
).toBe(true);
124124

125125
expect(
126126
log.dimensions.some(
127-
(d) => d.name === "testpack/testPost" && d.value === "postTest"
127+
(d) => d.name === "testpack/testPost" && d.value === "test_post_value"
128128
),
129129
"Logs post test capture"
130130
).toBe(true);

test/wasm/manifest.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
{
22
"schema": "pre2",
33
"name": "testpack",
4-
"version": "0.0.1",
5-
"description": "Test pack, never published to prod",
6-
"permissions": {},
7-
"fields": [],
4+
"version": "0.0.4",
5+
"description": "Test / example pack, never published to prod",
6+
"permissions": {
7+
"body": true
8+
},
9+
"fields": [
10+
{
11+
"name": "testField",
12+
"type": "string",
13+
"description": "Test field that should exist in the lifecycle",
14+
"default": "test_field_value"
15+
}
16+
],
817
"charts": []
918
}

test/wasm/pack.wasm

333 KB
Binary file not shown.

0 commit comments

Comments
 (0)