Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Errors to Notarization Progress #147

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/entries/Background/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export async function setNotaryRequestError(
export async function setNotaryRequestProgress(
id: string,
progress: RequestProgress,
errorMessage?: string,
): Promise<RequestHistory | null> {
const existing = await historyDb.get(id);

Expand All @@ -123,6 +124,7 @@ export async function setNotaryRequestProgress(
const newReq: RequestHistory = {
...existing,
progress,
errorMessage,
};

await historyDb.put(id, newReq);
Expand Down
15 changes: 12 additions & 3 deletions src/entries/Background/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,13 @@
SendingRequest,
ReadingTranscript,
FinalizingOutputs,
Error,
}

export function progressText(progress: RequestProgress): string {
export function progressText(
progress: RequestProgress,
errorMessage?: string,
): string {
switch (progress) {
case RequestProgress.CreatingProver:
return 'Creating prover...';
Expand All @@ -183,6 +187,10 @@
return 'Reading request transcript...';
case RequestProgress.FinalizingOutputs:
return 'Finalizing notarization outputs...';
case RequestProgress.Error:
return errorMessage

Check failure on line 191 in src/entries/Background/rpc.ts

View workflow job for this annotation

GitHub Actions / build

Replace `⏎········?·errorMessage⏎·······` with `·?·errorMessage`
? errorMessage
: 'Error: Notarization Failed';
}
}

Expand All @@ -208,6 +216,7 @@
secretHeaders?: string[];
secretResps?: string[];
cid?: string;
errorMessage?: string;
metadata?: {
[k: string]: string;
};
Expand Down Expand Up @@ -428,9 +437,9 @@
request: BackgroundAction,
sendResponse: (data?: any) => void,
) {
const { id, progress } = request.data;
const { id, progress, errorMessage } = request.data;

const newReq = await setNotaryRequestProgress(id, progress);
const newReq = await setNotaryRequestProgress(id, progress, errorMessage);
if (!newReq) return;
await pushToRedux(addRequestHistory(await getNotaryRequest(id)));

Expand Down
84 changes: 64 additions & 20 deletions src/entries/Offscreen/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,27 +452,45 @@
const hostname = urlify(url)?.hostname || '';
const notary = NotaryServer.from(notaryUrl);

updateRequestProgress(id, RequestProgress.CreatingProver);
const prover: TProver = await new Prover({
let prover: TProver;
prover = await handleProgress(

Check failure on line 456 in src/entries/Offscreen/rpc.ts

View workflow job for this annotation

GitHub Actions / build

'prover' is never reassigned. Use 'const' instead
id,
serverDns: hostname,
maxSentData,
maxRecvData,
});
RequestProgress.CreatingProver,
() => new Prover({

Check failure on line 459 in src/entries/Offscreen/rpc.ts

View workflow job for this annotation

GitHub Actions / build

Insert `⏎·····`
id,

Check failure on line 460 in src/entries/Offscreen/rpc.ts

View workflow job for this annotation

GitHub Actions / build

Insert `··`
serverDns: hostname,

Check failure on line 461 in src/entries/Offscreen/rpc.ts

View workflow job for this annotation

GitHub Actions / build

Insert `··`
maxSentData,

Check failure on line 462 in src/entries/Offscreen/rpc.ts

View workflow job for this annotation

GitHub Actions / build

Insert `··`
maxRecvData,

Check failure on line 463 in src/entries/Offscreen/rpc.ts

View workflow job for this annotation

GitHub Actions / build

Insert `··`
}),

Check failure on line 464 in src/entries/Offscreen/rpc.ts

View workflow job for this annotation

GitHub Actions / build

Replace `····` with `······`
'Error creating prover'

Check failure on line 465 in src/entries/Offscreen/rpc.ts

View workflow job for this annotation

GitHub Actions / build

Insert `,`
);

updateRequestProgress(id, RequestProgress.GettingSession);
const sessionUrl = await notary.sessionUrl(maxSentData, maxRecvData);
const sessionUrl = await handleProgress(
id,
RequestProgress.GettingSession,
() => notary.sessionUrl(maxSentData, maxRecvData),
'Error getting session from Notary'

Check failure on line 472 in src/entries/Offscreen/rpc.ts

View workflow job for this annotation

GitHub Actions / build

Insert `,`
);

updateRequestProgress(id, RequestProgress.SettingUpProver);
await prover.setup(sessionUrl);
await handleProgress(
id,
RequestProgress.SettingUpProver,
() => prover.setup(sessionUrl),
'Error setting up prover'
);

updateRequestProgress(id, RequestProgress.SendingRequest);
await prover.sendRequest(websocketProxyUrl + `?token=${hostname}`, {
url,
method,
headers,
body,
});
await handleProgress(
id,
RequestProgress.SendingRequest,
() =>
prover.sendRequest(websocketProxyUrl + `?token=${hostname}`, {
url,
method,
headers,
body,
}),
'Error sending request'
);

return prover;
}
Expand Down Expand Up @@ -505,13 +523,39 @@
return result;
}

function updateRequestProgress(id: string, progress: RequestProgress) {
devlog(`Request ${id}: ${progressText(progress)}`);
function updateRequestProgress(
id: string,
progress: RequestProgress,
errorMessage?: string,
) {
const progressMessage =
progress === RequestProgress.Error
? `${errorMessage || 'Notarization Failed'}`
: progressText(progress);
console.log('ERROR MESSAGE', progressMessage);
devlog(`Request ${id}: ${progressMessage}`);

browser.runtime.sendMessage({
type: BackgroundActiontype.update_request_progress,
data: {
id,
progress: progress,
progress,
errorMessage,
},
});
}

async function handleProgress<T>(
id: string,
progress: RequestProgress,
action: () => Promise<T>,
errorMessage: string,
): Promise<T> {
try {
updateRequestProgress(id, progress);
return await action();
} catch (error: any) {
updateRequestProgress(id, RequestProgress.Error, errorMessage);
throw error;
}
}
14 changes: 8 additions & 6 deletions src/entries/SidePanel/SidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,14 @@ function StepContent(
<button className="button mt-2 w-fit flex flex-row flex-nowrap items-center gap-2 cursor-default">
<Icon className="animate-spin" fa="fa-solid fa-spinner" size={1} />
<span className="text-sm">
{notaryRequest?.progress
? `(${(
((notaryRequest.progress + 1) / 6.06) *
100
).toFixed()}%) ${progressText(notaryRequest.progress)}`
: 'Pending...'}
{notaryRequest?.progress === 6
? `${progressText(notaryRequest.progress, notaryRequest?.errorMessage)}`
: notaryRequest?.progress
? `(${(
((notaryRequest.progress + 1) / 6.06) *
100
).toFixed()}%) ${progressText(notaryRequest.progress)}`
: 'Pending...'}
</span>
</button>
);
Expand Down
20 changes: 9 additions & 11 deletions src/pages/History/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import React, { ReactElement, useState, useCallback } from 'react';
import { useDispatch } from 'react-redux';
import { useNavigate } from 'react-router';
import {
useHistoryOrder,
useRequestHistory,
deleteRequestHistory,
} from '../../reducers/history';
import { useHistoryOrder, useRequestHistory } from '../../reducers/history';
import Icon from '../../components/Icon';
import NotarizeIcon from '../../assets/img/notarize.png';
import { getNotaryApi, getProxyApi } from '../../utils/storage';
Expand Down Expand Up @@ -110,12 +106,14 @@ export function OneRequestHistory(props: {
size={1}
/>
<span className="">
{request?.progress
? `(${(
((request.progress + 1) / 6.06) *
100
).toFixed()}%) ${progressText(request.progress)}`
: 'Pending...'}
{request?.progress === 6
? `${progressText(request.progress, request.errorMessage)}`
: request?.progress
? `(${(
((request.progress + 1) / 6.06) *
100
).toFixed()}%) ${progressText(request.progress)}`
: 'Pending...'}
</span>
</div>
)}
Expand Down
Loading