From 80d22b556c73ee47fe3b6dde3fac439602e236d3 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Thu, 27 Jun 2024 20:27:00 +0700 Subject: [PATCH] UBERF-7419: Fix various sentry errors (#5931) --- packages/core/src/operator.ts | 11 ++++-- .../src/components/DocPopup.svelte | 5 ++- packages/ui/src/colors.ts | 4 +- .../src/components/DropdownLabelsPopup.svelte | 3 ++ packages/ui/src/components/Separator.svelte | 6 +-- .../src/components/AddAttachment.svelte | 1 + .../src/components/AttachmentPopup.svelte | 1 + .../src/components/AttachmentRefInput.svelte | 1 + .../AttachmentStyleBoxCollabEditor.svelte | 1 + .../src/components/Attachments.svelte | 5 +-- .../src/components/Photos.svelte | 1 + plugins/client-resources/src/index.ts | 38 ++++++++++--------- .../src/components/DriveSpaceHeader.svelte | 1 + .../src/components/NewMessage.svelte | 1 + .../src/components/NewMessages.svelte | 1 + .../src/components/Guest.svelte | 4 +- .../src/components/ScheduleView.svelte | 11 ++++-- .../love-resources/src/components/Room.svelte | 4 +- .../src/components/VideoPopup.svelte | 2 +- plugins/love-resources/src/utils.ts | 1 + .../src/components/EditEnum.svelte | 1 + .../src/components/EnumValues.svelte | 1 + .../src/components/CreateIssue.svelte | 11 +++--- .../src/components/NewIssueHeader.svelte | 1 + .../src/components/Workbench.svelte | 4 +- 25 files changed, 76 insertions(+), 44 deletions(-) diff --git a/packages/core/src/operator.ts b/packages/core/src/operator.ts index 2f4f5b3f1e..e9151ffc7e 100644 --- a/packages/core/src/operator.ts +++ b/packages/core/src/operator.ts @@ -38,6 +38,9 @@ function $push (document: Doc, keyval: Record): void { arr.push(val) } } else { + if (doc[key] == null) { + doc[key] = [] + } doc[key].push(val) } } @@ -53,7 +56,7 @@ function $pull (document: Doc, keyval: Record): void { if (typeof keyval[key] === 'object' && keyval[key] !== null) { const { $in } = keyval[key] as PullArray - doc[key] = arr.filter((val) => { + doc[key] = (arr ?? []).filter((val) => { if ($in !== undefined) { return !$in.includes(val) } else { @@ -67,7 +70,7 @@ function $pull (document: Doc, keyval: Record): void { } }) } else { - doc[key] = arr.filter((val) => val !== keyval[key]) + doc[key] = (arr ?? []).filter((val) => val !== keyval[key]) } } } @@ -119,7 +122,7 @@ function $move (document: Doc, keyval: Record): void { } const arr = doc[key] as Array const desc = keyval[key] - doc[key] = arr.filter((val) => val !== desc.$value) + doc[key] = (arr ?? []).filter((val) => val !== desc.$value) doc[key].splice(desc.$position, 0, desc.$value) } } @@ -134,7 +137,7 @@ function $pushMixin (document: Doc, options: any): void { const keyval = options.values for (const key in keyval) { const arr = mixin[key] - if (arr === undefined) { + if (arr == null) { mixin[key] = [keyval[key]] } else { arr.push(keyval[key]) diff --git a/packages/presentation/src/components/DocPopup.svelte b/packages/presentation/src/components/DocPopup.svelte index e67e558e84..1e79379189 100644 --- a/packages/presentation/src/components/DocPopup.svelte +++ b/packages/presentation/src/components/DocPopup.svelte @@ -71,7 +71,10 @@ created.length > 0 || objects.map((it) => getObjectValue(groupBy, it)).filter((it, index, arr) => arr.indexOf(it) === index).length > 1 - const checkSelected = (item: Doc): void => { + const checkSelected = (item?: Doc): void => { + if (item === undefined) { + return + } if (selectedElements.has(item._id)) { selectedElements.delete(item._id) } else { diff --git a/packages/ui/src/colors.ts b/packages/ui/src/colors.ts index d36f760b64..2fe1c6984f 100644 --- a/packages/ui/src/colors.ts +++ b/packages/ui/src/colors.ts @@ -304,7 +304,9 @@ export function getPlatformColors (darkTheme: boolean): readonly ColorDefinition } function hashCode (str: string): number { - return str.split('').reduce((prevHash, currVal) => ((prevHash << 5) - prevHash + currVal.charCodeAt(0)) | 0, 0) + return (str ?? '') + .split('') + .reduce((prevHash, currVal) => ((prevHash << 5) - prevHash + currVal.charCodeAt(0)) | 0, 0) } /** diff --git a/packages/ui/src/components/DropdownLabelsPopup.svelte b/packages/ui/src/components/DropdownLabelsPopup.svelte index 0d4d75d947..1794e359af 100644 --- a/packages/ui/src/components/DropdownLabelsPopup.svelte +++ b/packages/ui/src/components/DropdownLabelsPopup.svelte @@ -41,6 +41,9 @@ async function handleSelection (evt: Event | undefined, selection: number): Promise { const item = objects[selection] + if (item == null) { + return + } if (multiselect && Array.isArray(selected)) { const index = selected.indexOf(item.id) if (index !== -1) { diff --git a/packages/ui/src/components/Separator.svelte b/packages/ui/src/components/Separator.svelte index 982fcba9ad..95461bb22d 100644 --- a/packages/ui/src/components/Separator.svelte +++ b/packages/ui/src/components/Separator.svelte @@ -208,10 +208,10 @@ const checkSizes = (): void => { if (sState === SeparatorState.FLOAT) { - if (parentElement) initSize(parentElement, panel) + if (parentElement != null && panel != null) initSize(parentElement, panel) } else if (sState === SeparatorState.NORMAL) { - if (prevElement) initSize(prevElement, prevElSize) - if (nextElement) initSize(nextElement, nextElSize, true) + if (prevElement != null && prevElSize != null) initSize(prevElement, prevElSize) + if (nextElement != null && nextElSize != null) initSize(nextElement, nextElSize, true) } } diff --git a/plugins/attachment-resources/src/components/AddAttachment.svelte b/plugins/attachment-resources/src/components/AddAttachment.svelte index bf4eb2832d..32843eefa0 100644 --- a/plugins/attachment-resources/src/components/AddAttachment.svelte +++ b/plugins/attachment-resources/src/components/AddAttachment.svelte @@ -69,6 +69,7 @@ name="file" id="file" style="display: none" + disabled={inputFile == null} on:change={fileSelected} /> diff --git a/plugins/attachment-resources/src/components/AttachmentPopup.svelte b/plugins/attachment-resources/src/components/AttachmentPopup.svelte index 6f6fae7339..08d7a45ce3 100644 --- a/plugins/attachment-resources/src/components/AttachmentPopup.svelte +++ b/plugins/attachment-resources/src/components/AttachmentPopup.svelte @@ -107,6 +107,7 @@ name="file" id="file" style="display: none" + disabled={inputFile == null} on:change={fileSelected} />
diff --git a/plugins/attachment-resources/src/components/AttachmentRefInput.svelte b/plugins/attachment-resources/src/components/AttachmentRefInput.svelte index 9bf6ed6677..817ec9ed83 100644 --- a/plugins/attachment-resources/src/components/AttachmentRefInput.svelte +++ b/plugins/attachment-resources/src/components/AttachmentRefInput.svelte @@ -308,6 +308,7 @@
{ const db = await dbPromise if (db !== undefined) { - const transaction = db.transaction('model', 'readwrite') // (1) - const models = transaction.objectStore('model') // (2) - const model = await new Promise<{ id: string, model: LoadModelResponse } | undefined>((resolve) => { - const storedValue: IDBRequest<{ id: string, model: LoadModelResponse }> = models.get(workspace) - storedValue.onsuccess = function () { - resolve(storedValue.result) - } - storedValue.onerror = function () { - resolve(undefined) - } - }) + try { + const transaction = db.transaction('model', 'readwrite') // (1) + const models = transaction.objectStore('model') // (2) + const model = await new Promise<{ id: string, model: LoadModelResponse } | undefined>((resolve) => { + const storedValue: IDBRequest<{ id: string, model: LoadModelResponse }> = models.get(workspace) + storedValue.onsuccess = function () { + resolve(storedValue.result) + } + storedValue.onerror = function () { + resolve(undefined) + } + }) - if (model == null) { - return { - full: false, - transactions: [], - hash: '' + if (model == null) { + return { + full: false, + transactions: [], + hash: '' + } } + return model.model + } catch (err: any) { + // Assume no model is stored. } - return model.model } return { full: true, diff --git a/plugins/drive-resources/src/components/DriveSpaceHeader.svelte b/plugins/drive-resources/src/components/DriveSpaceHeader.svelte index 46a54f693f..cd27d30bcc 100644 --- a/plugins/drive-resources/src/components/DriveSpaceHeader.svelte +++ b/plugins/drive-resources/src/components/DriveSpaceHeader.svelte @@ -107,6 +107,7 @@ {:else} (workbench.class.Application, { hidden: false, _id: { $nin: excludedApps } }) async function resolveShortLink (loc: Location): Promise { - if (loc.path[2] !== undefined && loc.path[2].trim().length > 0) { + if (loc.path[2] != null && loc.path[2].trim().length > 0) { const app = apps.find((p) => p.alias === loc.path[2]) if (app?.locationResolver) { const resolver = await getResource(app.locationResolver) @@ -181,7 +181,7 @@ if (fragment !== currentFragment) { currentFragment = fragment - if (fragment !== undefined && fragment.trim().length > 0) { + if (fragment != null && fragment.trim().length > 0) { await setOpenPanelFocus(fragment) } else { closePanel() diff --git a/plugins/hr-resources/src/components/ScheduleView.svelte b/plugins/hr-resources/src/components/ScheduleView.svelte index 7e56e75e43..2bd027f127 100644 --- a/plugins/hr-resources/src/components/ScheduleView.svelte +++ b/plugins/hr-resources/src/components/ScheduleView.svelte @@ -46,7 +46,7 @@ ? getEndDate(currentDate.getFullYear(), 11) : getEndDate(currentDate.getFullYear(), currentDate.getMonth()) - $: departments = [department, ...getDescendants(department, descendants)] + $: departments = [department, ...getDescendants(department, descendants, new Set())] $: staffIdsForOpenedDepartments = staff.filter((p) => departments.includes(p.department)).map((p) => p._id) const lq = createQuery() @@ -79,11 +79,16 @@ function getDescendants ( department: Ref, - descendants: Map, Department[]> + descendants: Map, Department[]>, + visited: Set ): Ref[] { const res = (descendants.get(department) ?? []).map((p) => p._id) for (const department of res) { - res.push(...getDescendants(department, descendants)) + const has = visited.has(department) + if (!has) { + visited.add(department) + res.push(...getDescendants(department, descendants, visited)) + } } return res } diff --git a/plugins/love-resources/src/components/Room.svelte b/plugins/love-resources/src/components/Room.svelte index 88be7fed7b..cfd07e4d4a 100644 --- a/plugins/love-resources/src/components/Room.svelte +++ b/plugins/love-resources/src/components/Room.svelte @@ -135,7 +135,7 @@ await tick() index = participants.findIndex((p) => p._id === participant.identity) const el = participantElements[index] - if (el !== undefined) { + if (el != null) { el.appendChild(element) return } @@ -180,7 +180,7 @@ return } const index = participants.findIndex((p) => p._id === participant.identity) - if (index !== -1) { + if (index !== -1 && participantElements[index] != null) { participantElements[index].setTrackMuted(publication.isMuted) } } else { diff --git a/plugins/love-resources/src/components/VideoPopup.svelte b/plugins/love-resources/src/components/VideoPopup.svelte index 35e420fef5..a52d5ebb37 100644 --- a/plugins/love-resources/src/components/VideoPopup.svelte +++ b/plugins/love-resources/src/components/VideoPopup.svelte @@ -168,7 +168,7 @@ return } const index = participants.findIndex((p) => p._id === participant.identity) - if (index !== -1) { + if (index !== -1 && participantElements[index] != null) { participantElements[index].setTrackMuted(publication.isMuted) } } else { diff --git a/plugins/love-resources/src/utils.ts b/plugins/love-resources/src/utils.ts index 271bbd7b19..eda4e33498 100644 --- a/plugins/love-resources/src/utils.ts +++ b/plugins/love-resources/src/utils.ts @@ -613,6 +613,7 @@ export async function tryConnect ( }) requestsQuery.query(love.class.JoinRequest, { person: (me as PersonAccount).person, _id }, (res) => { const req = res[0] + if (req === undefined) return if (req.status === RequestStatus.Pending) return requestsQuery.unsubscribe() if (req.status === RequestStatus.Approved) { diff --git a/plugins/setting-resources/src/components/EditEnum.svelte b/plugins/setting-resources/src/components/EditEnum.svelte index ace6cc2832..05e8233163 100644 --- a/plugins/setting-resources/src/components/EditEnum.svelte +++ b/plugins/setting-resources/src/components/EditEnum.svelte @@ -222,6 +222,7 @@ 0 && object.status !== undefined && kind !== undefined && @@ -343,8 +346,6 @@ const dispatch = createEventDispatcher() const spaceQuery = createQuery() - let descriptionBox: AttachmentStyledBox - const key: KeyedAttribute = { key: 'labels', attr: client.getHierarchy().getAttribute(tracker.class.Issue, 'labels') @@ -513,7 +514,7 @@ } await operations.commit() - await descriptionBox.createAttachments(_id) + await descriptionBox?.createAttachments(_id) const parents: IssueParentInfo[] = parentIssue != null @@ -986,7 +987,7 @@ showPreview removable on:remove={(result) => { - if (result.detail !== undefined) descriptionBox.removeAttachmentById(result.detail._id) + if (result.detail !== undefined) descriptionBox?.removeAttachmentById(result.detail._id) }} /> {/each} @@ -1000,7 +1001,7 @@ size={'large'} kind={'ghost'} on:click={() => { - descriptionBox.handleAttach() + descriptionBox?.handleAttach() }} /> diff --git a/plugins/tracker-resources/src/components/NewIssueHeader.svelte b/plugins/tracker-resources/src/components/NewIssueHeader.svelte index a6e42d33ce..0ab4bad9f4 100644 --- a/plugins/tracker-resources/src/components/NewIssueHeader.svelte +++ b/plugins/tracker-resources/src/components/NewIssueHeader.svelte @@ -100,6 +100,7 @@
{ let locationResolver = currentApplication?.locationResolver - if (loc.path[2] !== undefined && loc.path[2].trim().length > 0) { + if (loc.path[2] != null && loc.path[2].trim().length > 0) { const app = apps.find((p) => p.alias === loc.path[2]) if (app?.locationResolver) { locationResolver = app?.locationResolver @@ -391,7 +391,7 @@ currentQuery = loc.query if (fragment !== currentFragment) { currentFragment = fragment - if (fragment !== undefined && fragment.trim().length > 0) { + if (fragment != null && fragment.trim().length > 0) { await setOpenPanelFocus(fragment) } else { closePanel()