mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
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:
parent
57f25855d3
commit
907a95a746
70 changed files with 312 additions and 282 deletions
|
|
@ -28,10 +28,14 @@ describe('Executor Queue test', function () {
|
|||
});
|
||||
|
||||
// The first 3 should be finished within 200ms (concurrency 3)
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
eq.addTask(() => timeoutPromiseBuilder(100, 'T1'));
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
eq.addTask(() => timeoutPromiseBuilder(200, 'T2'));
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
eq.addTask(() => timeoutPromiseBuilder(150, 'T3'));
|
||||
// The last task will be executed after 200ms and will finish at 400ms
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
eq.addTask(() => timeoutPromiseBuilder(200, 'T4'));
|
||||
|
||||
expect(finished).not.toBeCalled();
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { handlePromiseError } from '$lib/utils';
|
||||
|
||||
interface Options {
|
||||
concurrency: number;
|
||||
}
|
||||
|
|
@ -66,6 +68,6 @@ export class ExecutorQueue {
|
|||
return;
|
||||
}
|
||||
|
||||
runnable();
|
||||
handlePromiseError(runnable());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ export const openFileUploadDialog = async (albumId?: string | undefined) => {
|
|||
fileSelector.type = 'file';
|
||||
fileSelector.multiple = true;
|
||||
fileSelector.accept = extensions.join(',');
|
||||
fileSelector.addEventListener('change', async (e: Event) => {
|
||||
fileSelector.addEventListener('change', (e: Event) => {
|
||||
const target = e.target as HTMLInputElement;
|
||||
if (!target.files) {
|
||||
return;
|
||||
|
|
@ -119,7 +119,7 @@ async function fileUploader(asset: File, albumId: string | undefined = undefined
|
|||
}
|
||||
})
|
||||
.catch(async (error) => {
|
||||
await handleError(error, 'Unable to upload file');
|
||||
handleError(error, 'Unable to upload file');
|
||||
const reason = (await getServerErrorMessage(error)) || error;
|
||||
uploadAssetsStore.updateAsset(deviceAssetId, { state: UploadState.ERROR, error: reason });
|
||||
return undefined;
|
||||
|
|
|
|||
|
|
@ -22,20 +22,25 @@ export async function getServerErrorMessage(error: unknown) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function handleError(error: unknown, message: string) {
|
||||
export function handleError(error: unknown, message: string) {
|
||||
if ((error as Error)?.name === 'AbortError') {
|
||||
return;
|
||||
}
|
||||
|
||||
console.error(`[handleError]: ${message}`, error, (error as Error)?.stack);
|
||||
|
||||
let serverMessage = await getServerErrorMessage(error);
|
||||
if (serverMessage) {
|
||||
serverMessage = `${String(serverMessage).slice(0, 75)}\n(Immich Server Error)`;
|
||||
}
|
||||
getServerErrorMessage(error)
|
||||
.then((serverMessage) => {
|
||||
if (serverMessage) {
|
||||
serverMessage = `${String(serverMessage).slice(0, 75)}\n(Immich Server Error)`;
|
||||
}
|
||||
|
||||
notificationController.show({
|
||||
message: serverMessage || message,
|
||||
type: NotificationType.Error,
|
||||
});
|
||||
notificationController.show({
|
||||
message: serverMessage || message,
|
||||
type: NotificationType.Error,
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue