Skip to content

Commit

Permalink
fix: throw main error for last task
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Jan 24, 2022
1 parent 0b904ba commit 47300fe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/lib/sandbox/main-access-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ export const mainAccessHandler = async (
let applyPath: ApplyPath;
let instance: any;
let rtnValue: any;
let isLast: boolean;

for (; i < totalTasks; i++) {
try {
isLast = i === totalTasks - 1;
task = accessReq.$tasks$[i];
winId = task.$winId$;
applyPath = task.$applyPath$;
Expand Down Expand Up @@ -62,7 +64,7 @@ export const mainAccessHandler = async (
// get the existing instance
instance = getInstance(winId, task.$instanceId$);
if (instance) {
rtnValue = applyToInstance(worker, instance, applyPath, task.$groupedGetters$);
rtnValue = applyToInstance(worker, instance, applyPath, isLast, task.$groupedGetters$);

if (task.$assignInstanceId$) {
setInstanceId(rtnValue, task.$assignInstanceId$);
Expand All @@ -85,7 +87,7 @@ export const mainAccessHandler = async (
}
}
} catch (e: any) {
if (i === totalTasks - 1) {
if (isLast!) {
// last task is the only one we can throw a sync error
accessRsp.$error$ = String(e.stack || e);
} else {
Expand All @@ -103,6 +105,7 @@ const applyToInstance = (
worker: PartytownWebWorker,
instance: any,
applyPath: ApplyPath,
isLast: boolean,
groupedGetters?: string[]
) => {
let i = 0;
Expand Down Expand Up @@ -162,10 +165,14 @@ const applyToInstance = (
}
}
} catch (err) {
if (debug) {
console.debug(`Non-blocking setter error:`, err);
if (isLast) {
throw err;
} else {
console.debug(err);
if (debug) {
console.debug(`Non-blocking setter error:`, err);
} else {
console.debug(err);
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/lib/sandbox/read-main-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const readNextScript = (worker: PartytownWebWorker, winCtx: MainWindowCon
// it's possible for an iframe that's been appended
// to the DOM to not be ready yet
scriptElm = doc.querySelector<HTMLScriptElement>(blockingScriptSelector);
console.log('readNextScript', scriptElm);

if (!scriptElm) {
// first query for partytown scripts are blocking scripts that
Expand Down

1 comment on commit 47300fe

@vercel
Copy link

@vercel vercel bot commented on 47300fe Jan 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.