chore(web): cleanup promise handling (#7382)

* no-misused-promises

* no-floating-promises

* format

* revert for now

* remove load function

* require-await

* revert a few no-floating-promises changes that would cause no-misused-promises failures

* format

* fix a few more

* fix most remaining errors

* executor-queue

* executor-queue.spec

* remove duplicate comments by grouping rules

* upgrade sveltekit and enforce rules

* oops. move await

* try this

* just ignore for now since it's only a test

* run in parallel

* Update web/src/routes/admin/jobs-status/+page.svelte

Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com>

* remove Promise.resolve call

* rename function

* remove unnecessary warning silencing

* make handleError sync

* fix new errors from recently merged PR to main

* extract method

* use handlePromiseError

---------

Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
Ben McCann
2024-02-27 08:37:37 -08:00
committed by GitHub
parent 57f25855d3
commit 907a95a746
70 changed files with 312 additions and 282 deletions

View File

@@ -1,7 +1,7 @@
<script lang="ts">
import Icon from '$lib/components/elements/icon.svelte';
import { timeBeforeShowLoadingSpinner } from '$lib/constants';
import { getAssetThumbnailUrl } from '$lib/utils';
import { getAssetThumbnailUrl, handlePromiseError } from '$lib/utils';
import { getAssetType } from '$lib/utils/asset-utils';
import { autoGrowHeight } from '$lib/utils/autogrow';
import { clickOutside } from '$lib/utils/click-outside';
@@ -79,7 +79,7 @@
$: {
if (assetId && previousAssetId != assetId) {
getReactions();
handlePromiseError(getReactions());
previousAssetId = assetId;
}
}
@@ -95,10 +95,10 @@
}
};
const handleEnter = (event: KeyboardEvent) => {
const handleEnter = async (event: KeyboardEvent) => {
if (event.key === 'Enter') {
event.preventDefault();
handleSendComment();
await handleSendComment();
return;
}
};

View File

@@ -10,7 +10,7 @@
import { SlideshowState, slideshowStore } from '$lib/stores/slideshow.store';
import { stackAssetsStore } from '$lib/stores/stacked-asset.store';
import { user } from '$lib/stores/user.store';
import { getAssetJobMessage, isSharedLink } from '$lib/utils';
import { getAssetJobMessage, isSharedLink, handlePromiseError } from '$lib/utils';
import { addAssetsToAlbum, downloadFile } from '$lib/utils/asset-utils';
import { handleError } from '$lib/utils/handle-error';
import { shouldIgnoreShortcut } from '$lib/utils/shortcut';
@@ -174,8 +174,8 @@
$: {
if (isShared && asset.id) {
getFavorite();
getNumberOfComments();
handlePromiseError(getFavorite());
handlePromiseError(getNumberOfComments());
}
}
@@ -184,9 +184,9 @@
if (value === SlideshowState.PlaySlideshow) {
slideshowHistory.reset();
slideshowHistory.queue(asset.id);
handlePlaySlideshow();
handlePromiseError(handlePlaySlideshow());
} else if (value === SlideshowState.StopSlideshow) {
handleStopSlideshow();
handlePromiseError(handleStopSlideshow());
}
});
@@ -226,7 +226,7 @@
}
});
$: asset.id && !sharedLink && handleGetAllAlbums(); // Update the album information when the asset ID changes
$: asset.id && !sharedLink && handlePromiseError(handleGetAllAlbums()); // Update the album information when the asset ID changes
const handleGetAllAlbums = async () => {
if (isSharedLink()) {
@@ -247,7 +247,7 @@
isShowActivity = !isShowActivity;
};
const handleKeypress = (event: KeyboardEvent) => {
const handleKeypress = async (event: KeyboardEvent) => {
if (shouldIgnoreShortcut(event)) {
return;
}
@@ -264,7 +264,7 @@
case 'a':
case 'A': {
if (shiftKey) {
toggleArchive();
await toggleArchive();
}
return;
}
@@ -273,18 +273,18 @@
return;
}
case 'ArrowRight': {
navigateAssetForward();
await navigateAssetForward();
return;
}
case 'd':
case 'D': {
if (shiftKey) {
downloadFile(asset);
await downloadFile(asset);
}
return;
}
case 'Delete': {
trashOrDelete(shiftKey);
await trashOrDelete(shiftKey);
return;
}
case 'Escape': {
@@ -296,7 +296,7 @@
return;
}
case 'f': {
toggleFavorite();
await toggleFavorite();
return;
}
case 'i': {
@@ -326,7 +326,7 @@
slideshowHistory.queue(asset.id);
setAssetId(asset.id);
await setAssetId(asset.id);
$restartSlideshowProgress = true;
};
@@ -369,17 +369,17 @@
$isShowDetail = !$isShowDetail;
};
const trashOrDelete = (force: boolean = false) => {
const trashOrDelete = async (force: boolean = false) => {
if (force || !isTrashEnabled) {
if ($showDeleteModal) {
isShowDeleteConfirmation = true;
return;
}
deleteAsset();
await deleteAsset();
return;
}
trashAsset();
await trashAsset();
return;
};
@@ -432,7 +432,7 @@
message: asset.isFavorite ? `Added to favorites` : `Removed from favorites`,
});
} catch (error) {
await handleError(error, `Unable to ${asset.isFavorite ? `add asset to` : `remove asset from`} favorites`);
handleError(error, `Unable to ${asset.isFavorite ? `add asset to` : `remove asset from`} favorites`);
}
};
@@ -472,7 +472,7 @@
message: asset.isArchived ? `Added to archive` : `Removed from archive`,
});
} catch (error) {
await handleError(error, `Unable to ${asset.isArchived ? `add asset to` : `remove asset from`} archive`);
handleError(error, `Unable to ${asset.isArchived ? `add asset to` : `remove asset from`} archive`);
}
};
@@ -481,7 +481,7 @@
await runAssetJobs({ assetJobsDto: { assetIds: [asset.id], name } });
notificationController.show({ type: NotificationType.Info, message: getAssetJobMessage(name) });
} catch (error) {
await handleError(error, `Unable to submit job`);
handleError(error, `Unable to submit job`);
}
};
@@ -492,7 +492,7 @@
let assetViewerHtmlElement: HTMLElement;
const slideshowHistory = new SlideshowHistory((assetId: string) => {
setAssetId(assetId);
handlePromiseError(setAssetId(assetId));
$restartSlideshowProgress = true;
});
@@ -550,7 +550,7 @@
dispatch('close');
notificationController.show({ type: NotificationType.Info, message: 'Un-stacked', timeout: 1500 });
} catch (error) {
await handleError(error, `Unable to unstack`);
handleError(error, `Unable to unstack`);
}
};
</script>

View File

@@ -7,7 +7,7 @@
import { featureFlags } from '$lib/stores/server-config.store';
import { user } from '$lib/stores/user.store';
import { websocketEvents } from '$lib/stores/websocket';
import { getAssetThumbnailUrl, getPeopleThumbnailUrl, isSharedLink } from '$lib/utils';
import { getAssetThumbnailUrl, getPeopleThumbnailUrl, isSharedLink, handlePromiseError } from '$lib/utils';
import { delay, getAssetFilename } from '$lib/utils/asset-utils';
import { autoGrowHeight } from '$lib/utils/autogrow';
import { clickOutside } from '$lib/utils/click-outside';
@@ -78,7 +78,7 @@
originalDescription = description;
};
$: handleNewAsset(asset);
$: handlePromiseError(handleNewAsset(asset));
$: latlng = (() => {
const lat = asset.exifInfo?.latitude;
@@ -113,7 +113,7 @@
switch (event.key) {
case 'Enter': {
if (ctrl && event.target === textArea) {
handleFocusOut();
await handleFocusOut();
}
}
}

View File

@@ -4,7 +4,7 @@
import { boundingBoxesArray } from '$lib/stores/people.store';
import { alwaysLoadOriginalFile } from '$lib/stores/preferences.store';
import { photoZoomState } from '$lib/stores/zoom-image.store';
import { getKey } from '$lib/utils';
import { getKey, handlePromiseError } from '$lib/utils';
import { isWebCompatibleImage } from '$lib/utils/asset-utils';
import { getBoundingBox } from '$lib/utils/people-utils';
import { shouldIgnoreShortcut } from '$lib/utils/shortcut';
@@ -102,7 +102,7 @@
}
};
const doZoomImage = async () => {
const doZoomImage = () => {
setZoomImageWheelState({
currentZoom: $zoomImageWheelState.currentZoom === 1 ? 2 : 1,
});
@@ -120,7 +120,7 @@
if (state.currentZoom > 1 && isWebCompatibleImage(asset) && !hasZoomed && !$alwaysLoadOriginalFile) {
hasZoomed = true;
loadAssetData({ loadOriginal: true });
handlePromiseError(loadAssetData({ loadOriginal: true }));
}
});
</script>

View File

@@ -20,7 +20,7 @@
video.muted = false;
dispatch('onVideoStarted');
} catch (error) {
await handleError(error, 'Unable to play video');
handleError(error, 'Unable to play video');
} finally {
isVideoLoading = false;
}