refactor: remove ErrTuple pattern
This commit is contained in:
parent
46a71bdfee
commit
dc9e4f13e9
|
@ -1,7 +1,5 @@
|
|||
import {
|
||||
addContextToErr,
|
||||
downloadSmallObject,
|
||||
Err,
|
||||
maybeInitDefaultPortals,
|
||||
setActivePortalMasterKey,
|
||||
} from "@lumeweb/libweb";
|
||||
|
@ -13,6 +11,7 @@ import {
|
|||
} from "./vars.js";
|
||||
import { getStoredUserKey } from "./storage.js";
|
||||
import { readableStreamToBlob } from "binconv";
|
||||
import { addContextToErr } from "@lumeweb/libkernel";
|
||||
|
||||
export function boot() {
|
||||
let userKey;
|
||||
|
@ -38,19 +37,20 @@ export function boot() {
|
|||
}
|
||||
|
||||
export async function loadKernel() {
|
||||
let [, portalLoadErr] = maybeInitDefaultPortals();
|
||||
if (portalLoadErr) {
|
||||
let err = addContextToErr(portalLoadErr, "unable to init portals");
|
||||
try {
|
||||
maybeInitDefaultPortals();
|
||||
} catch (e) {
|
||||
let err = addContextToErr(e, "unable to init portals");
|
||||
setKernelLoaded(err);
|
||||
logErr(err);
|
||||
sendAuthUpdate();
|
||||
return;
|
||||
}
|
||||
|
||||
let [kernelCode, err] = await downloadDefaultKernel();
|
||||
|
||||
if (err !== null) {
|
||||
let extErr = addContextToErr(err, "unable to download kernel");
|
||||
let kernelCode;
|
||||
try {
|
||||
kernelCode = await downloadDefaultKernel();
|
||||
} catch (e) {
|
||||
let extErr = addContextToErr(e, "unable to download kernel");
|
||||
setKernelLoaded(extErr);
|
||||
logErr(extErr);
|
||||
sendAuthUpdate();
|
||||
|
@ -97,20 +97,10 @@ export async function loadKernel() {
|
|||
}
|
||||
}
|
||||
|
||||
async function downloadKernel(
|
||||
kernelCid: string,
|
||||
): Promise<[kernelCode: ReadableStream, err: Err]> {
|
||||
const [code, err] = await downloadSmallObject(kernelCid);
|
||||
|
||||
if (err != null) {
|
||||
return [null as any, err];
|
||||
}
|
||||
|
||||
return [code, null];
|
||||
async function downloadKernel(kernelCid: string): Promise<ReadableStream> {
|
||||
return await downloadSmallObject(kernelCid);
|
||||
}
|
||||
|
||||
function downloadDefaultKernel(): Promise<
|
||||
[kernelCode: ReadableStream, err: Err]
|
||||
> {
|
||||
function downloadDefaultKernel(): Promise<ReadableStream> {
|
||||
return downloadKernel(defaultKernelLink);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import {
|
||||
addContextToErr,
|
||||
bytesToHex,
|
||||
hexToBytes,
|
||||
setActivePortalMasterKey,
|
||||
} from "@lumeweb/libweb";
|
||||
import { addContextToErr } from "@lumeweb/libkernel";
|
||||
import {
|
||||
getLoginComplete,
|
||||
getLogoutComplete,
|
||||
|
|
|
@ -3,7 +3,7 @@ import {
|
|||
getLoginComplete,
|
||||
getLogoutComplete,
|
||||
} from "./vars.js";
|
||||
import { objAsString } from "@lumeweb/libweb";
|
||||
import { objAsString } from "@lumeweb/libkernel";
|
||||
|
||||
export function sendAuthUpdate() {
|
||||
window.parent.postMessage(
|
||||
|
|
Loading…
Reference in New Issue