diff --git a/web/apps/photos/src/services/upload/upload-service.ts b/web/apps/photos/src/services/upload/upload-service.ts index c08a08ad60..6afe1e02db 100644 --- a/web/apps/photos/src/services/upload/upload-service.ts +++ b/web/apps/photos/src/services/upload/upload-service.ts @@ -38,7 +38,7 @@ import { import { detectFileTypeInfoFromChunk } from "@/new/photos/utils/detect-type"; import { readStream } from "@/new/photos/utils/native-stream"; import { mergeUint8Arrays } from "@/utils/array"; -import { ensure, ensureInteger, ensureNumber } from "@/utils/ensure"; +import { ensureInteger, ensureNumber } from "@/utils/ensure"; import { CustomError, handleUploadError } from "@ente/shared/error"; import { addToCollection } from "services/collectionService"; import { @@ -857,7 +857,7 @@ const readImageOrVideoDetails = async (uploadItem: UploadItem) => { const fileTypeInfo = await detectFileTypeInfoFromChunk(async () => { const reader = stream.getReader(); - const chunk = ensure((await reader.read()).value); + const chunk = (await reader.read())!.value; await reader.cancel(); return chunk; }, uploadItemFileName(uploadItem)); diff --git a/web/apps/photos/src/utils/photoFrame/index.ts b/web/apps/photos/src/utils/photoFrame/index.ts index 3665478a05..8d752d1bd8 100644 --- a/web/apps/photos/src/utils/photoFrame/index.ts +++ b/web/apps/photos/src/utils/photoFrame/index.ts @@ -168,7 +168,7 @@ export const handleSelectCreator = collectionID: 0, context: { mode: selected.context?.mode, - personID: ensure(activePersonID), + personID: activePersonID!, }, }; } @@ -183,7 +183,7 @@ export const handleSelectCreator = collectionID: 0, context: { mode: selected.context?.mode, - collectionID: ensure(activeCollectionID), + collectionID: activeCollectionID!, }, }; } @@ -194,8 +194,8 @@ export const handleSelectCreator = const newContext: SelectionContext | undefined = !mode ? undefined : mode == "people" - ? { mode, personID: ensure(activePersonID) } - : { mode, collectionID: ensure(activeCollectionID) }; + ? { mode, personID: activePersonID! } + : { mode, collectionID: activeCollectionID! }; const handleCounterChange = (count: number) => { if (selected[id] === checked) { diff --git a/web/packages/base/local-user.ts b/web/packages/base/local-user.ts index 5a3eeafaac..c2a446eb3c 100644 --- a/web/packages/base/local-user.ts +++ b/web/packages/base/local-user.ts @@ -1,6 +1,5 @@ // TODO: This file belongs to the accounts package -import { ensure } from "@/utils/ensure"; import { z } from "zod"; import { getKVS } from "./kv"; @@ -57,4 +56,8 @@ export const ensureLocalUser = (): LocalUser => { * The underlying data is stored in IndexedDB, and can be accessed from web * workers. */ -export const ensureAuthToken = async () => ensure(await getKVS("token")); +export const ensureAuthToken = async () => { + const token = await getKVS("token"); + if (!token) throw new Error("Not logged in"); + return token; +}; diff --git a/web/packages/utils/ensure.ts b/web/packages/utils/ensure.ts index a7508eb8ad..ec31167a68 100644 --- a/web/packages/utils/ensure.ts +++ b/web/packages/utils/ensure.ts @@ -1,17 +1,3 @@ -/** - * Throw an exception if the given value is `null` or `undefined`. - * - * This is different from TypeScript's built in null assertion operator `!` in - * that `ensure` involves a runtime check, and will throw if the given value is - * null-ish. On the other hand the TypeScript null assertion is only an - * indication to the type system and does not involve any runtime checks. - */ -export const ensure = (v: T | null | undefined): T => { - if (v === null) throw new Error("Required value was null"); - if (v === undefined) throw new Error("Required value was undefined"); - return v; -}; - /** * Throw an exception if the given value is not a string. */