refactor: remove ErrTuple pattern

This commit is contained in:
Derrick Hammer 2023-09-08 13:56:42 -04:00
parent 46a71bdfee
commit dc9e4f13e9
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 15 additions and 25 deletions

View File

@ -1,7 +1,5 @@
import { import {
addContextToErr,
downloadSmallObject, downloadSmallObject,
Err,
maybeInitDefaultPortals, maybeInitDefaultPortals,
setActivePortalMasterKey, setActivePortalMasterKey,
} from "@lumeweb/libweb"; } from "@lumeweb/libweb";
@ -13,6 +11,7 @@ import {
} from "./vars.js"; } from "./vars.js";
import { getStoredUserKey } from "./storage.js"; import { getStoredUserKey } from "./storage.js";
import { readableStreamToBlob } from "binconv"; import { readableStreamToBlob } from "binconv";
import { addContextToErr } from "@lumeweb/libkernel";
export function boot() { export function boot() {
let userKey; let userKey;
@ -38,19 +37,20 @@ export function boot() {
} }
export async function loadKernel() { export async function loadKernel() {
let [, portalLoadErr] = maybeInitDefaultPortals(); try {
if (portalLoadErr) { maybeInitDefaultPortals();
let err = addContextToErr(portalLoadErr, "unable to init portals"); } catch (e) {
let err = addContextToErr(e, "unable to init portals");
setKernelLoaded(err); setKernelLoaded(err);
logErr(err); logErr(err);
sendAuthUpdate(); sendAuthUpdate();
return; return;
} }
let kernelCode;
let [kernelCode, err] = await downloadDefaultKernel(); try {
kernelCode = await downloadDefaultKernel();
if (err !== null) { } catch (e) {
let extErr = addContextToErr(err, "unable to download kernel"); let extErr = addContextToErr(e, "unable to download kernel");
setKernelLoaded(extErr); setKernelLoaded(extErr);
logErr(extErr); logErr(extErr);
sendAuthUpdate(); sendAuthUpdate();
@ -97,20 +97,10 @@ export async function loadKernel() {
} }
} }
async function downloadKernel( async function downloadKernel(kernelCid: string): Promise<ReadableStream> {
kernelCid: string, return await downloadSmallObject(kernelCid);
): Promise<[kernelCode: ReadableStream, err: Err]> {
const [code, err] = await downloadSmallObject(kernelCid);
if (err != null) {
return [null as any, err];
} }
return [code, null]; function downloadDefaultKernel(): Promise<ReadableStream> {
}
function downloadDefaultKernel(): Promise<
[kernelCode: ReadableStream, err: Err]
> {
return downloadKernel(defaultKernelLink); return downloadKernel(defaultKernelLink);
} }

View File

@ -1,9 +1,9 @@
import { import {
addContextToErr,
bytesToHex, bytesToHex,
hexToBytes, hexToBytes,
setActivePortalMasterKey, setActivePortalMasterKey,
} from "@lumeweb/libweb"; } from "@lumeweb/libweb";
import { addContextToErr } from "@lumeweb/libkernel";
import { import {
getLoginComplete, getLoginComplete,
getLogoutComplete, getLogoutComplete,

View File

@ -3,7 +3,7 @@ import {
getLoginComplete, getLoginComplete,
getLogoutComplete, getLogoutComplete,
} from "./vars.js"; } from "./vars.js";
import { objAsString } from "@lumeweb/libweb"; import { objAsString } from "@lumeweb/libkernel";
export function sendAuthUpdate() { export function sendAuthUpdate() {
window.parent.postMessage( window.parent.postMessage(