avoid logging url already set error for known cases

This commit is contained in:
Abhinav 2023-12-07 14:56:40 +05:30
parent cb362e17e7
commit 5f1d932647
3 changed files with 42 additions and 49 deletions

View file

@ -20,6 +20,7 @@ import { PHOTOS_PAGES } from '@ente/shared/constants/pages';
import { PhotoList } from './PhotoList'; import { PhotoList } from './PhotoList';
import { DedupePhotoList } from './PhotoList/dedupe'; import { DedupePhotoList } from './PhotoList/dedupe';
import { Duplicate } from 'services/deduplicationService'; import { Duplicate } from 'services/deduplicationService';
import { CustomError } from '@ente/shared/error';
const Container = styled('div')` const Container = styled('div')`
display: block; display: block;
@ -176,21 +177,12 @@ const PhotoFrame = ({
// this is to prevent outdated updateURL call from updating the wrong file // this is to prevent outdated updateURL call from updating the wrong file
if (file.id !== id) { if (file.id !== id) {
addLogLine( addLogLine(
`PhotoSwipe: updateURL: file id mismatch: ${file.id} !== ${id}` `[${id}]PhotoSwipe: updateURL: file id mismatch: ${file.id} !== ${id}`
); );
return; throw Error(CustomError.UPDATE_URL_FILE_ID_MISMATCH);
} }
if (file.msrc && file.msrc !== url && !forceUpdate) { if (file.msrc && !forceUpdate) {
addLogLine( throw Error(CustomError.URL_ALREADY_SET);
`PhotoSwipe: updateURL: msrc already set: ${file.msrc}`
);
logError(
new Error(
`PhotoSwipe: updateURL: msrc already set: ${file.msrc}`
),
'PhotoSwipe: updateURL called with msrc already set'
);
return;
} }
updateFileMsrcProps(file, url); updateFileMsrcProps(file, url);
}; };
@ -205,32 +197,17 @@ const PhotoFrame = ({
// this is to prevent outdate updateSrcURL call from updating the wrong file // this is to prevent outdate updateSrcURL call from updating the wrong file
if (file.id !== id) { if (file.id !== id) {
addLogLine( addLogLine(
`PhotoSwipe: updateSrcURL: file id mismatch: ${file.id} !== ${id}` `[${id}]PhotoSwipe: updateSrcURL: file id mismatch: ${file.id} !== ${id}`
); );
return; throw Error(CustomError.UPDATE_URL_FILE_ID_MISMATCH);
} }
if (file.isSourceLoaded && !forceUpdate) { if (file.isSourceLoaded && !forceUpdate) {
addLogLine( throw Error(CustomError.URL_ALREADY_SET);
`PhotoSwipe: updateSrcURL: source already loaded: ${file.id}`
);
logError(
new Error(
`PhotoSwipe: updateSrcURL: source already loaded: ${file.id}`
),
'PhotoSwipe updateSrcURL called when source already loaded'
);
return;
} else if (file.conversionFailed) { } else if (file.conversionFailed) {
addLogLine( addLogLine(
`PhotoSwipe: updateSrcURL: conversion failed: ${file.id}` `[${id}]PhotoSwipe: updateSrcURL: conversion failed: ${file.id}`
); );
logError( throw Error(CustomError.FILE_CONVERSION_FAILED);
new Error(
`PhotoSwipe: updateSrcURL: conversion failed: ${file.id}`
),
'PhotoSwipe updateSrcURL called when conversion failed'
);
return;
} }
await updateFileSrcProps(file, srcURLs); await updateFileSrcProps(file, srcURLs);
@ -386,8 +363,8 @@ const PhotoFrame = ({
addLogLine(`[${item.id}] doesn't have thumbnail`); addLogLine(`[${item.id}] doesn't have thumbnail`);
thumbFetching[item.id] = true; thumbFetching[item.id] = true;
const url = await DownloadManager.getThumbnailForPreview(item); const url = await DownloadManager.getThumbnailForPreview(item);
updateURL(index)(item.id, url);
try { try {
updateURL(index)(item.id, url);
addLogLine( addLogLine(
`[${ `[${
item.id item.id
@ -398,10 +375,12 @@ const PhotoFrame = ({
instance.updateSize(true); instance.updateSize(true);
} }
} catch (e) { } catch (e) {
logError( if (e.message !== CustomError.URL_ALREADY_SET) {
e, logError(
'updating photoswipe after msrc url update failed' e,
); 'updating photoswipe after msrc url update failed'
);
}
// ignore // ignore
} }
} catch (e) { } catch (e) {
@ -427,12 +406,9 @@ const PhotoFrame = ({
try { try {
addLogLine(`[${item.id}] new file src request`); addLogLine(`[${item.id}] new file src request`);
fetching[item.id] = true; fetching[item.id] = true;
const srcURLs = await DownloadManager.getFileForPreview(item); const srcURLs = await DownloadManager.getFileForPreview(item);
await updateSrcURL(index, item.id, srcURLs);
try { try {
await updateSrcURL(index, item.id, srcURLs);
addLogLine( addLogLine(
`[${item.id}] calling invalidateCurrItems for src, source loaded :${item.isSourceLoaded}` `[${item.id}] calling invalidateCurrItems for src, source loaded :${item.isSourceLoaded}`
); );
@ -441,7 +417,12 @@ const PhotoFrame = ({
instance.updateSize(true); instance.updateSize(true);
} }
} catch (e) { } catch (e) {
logError(e, 'updating photoswipe after src url update failed'); if (e.message !== CustomError.URL_ALREADY_SET) {
logError(
e,
'updating photoswipe after src url update failed'
);
}
throw e; throw e;
} }
} catch (e) { } catch (e) {
@ -473,8 +454,8 @@ const PhotoFrame = ({
); );
return; return;
} }
updateURL(index)(item.id, item.msrc, true);
try { try {
updateURL(index)(item.id, item.msrc, true);
addLogLine( addLogLine(
`[${ `[${
item.id item.id
@ -485,7 +466,9 @@ const PhotoFrame = ({
instance.updateSize(true); instance.updateSize(true);
} }
} catch (e) { } catch (e) {
logError(e, 'updating photoswipe after msrc url update failed'); if (e.message !== CustomError.URL_ALREADY_SET) {
logError(e, 'updating photoswipe after msrc url update failed');
}
// ignore // ignore
} }
try { try {
@ -496,9 +479,8 @@ const PhotoFrame = ({
const srcURL = await DownloadManager.getFileForPreview(item, true); const srcURL = await DownloadManager.getFileForPreview(item, true);
await updateSrcURL(index, item.id, srcURL, true);
try { try {
await updateSrcURL(index, item.id, srcURL, true);
addLogLine( addLogLine(
`[${item.id}] calling invalidateCurrItems for src, source loaded :${item.isSourceLoaded}` `[${item.id}] calling invalidateCurrItems for src, source loaded :${item.isSourceLoaded}`
); );
@ -507,7 +489,12 @@ const PhotoFrame = ({
instance.updateSize(true); instance.updateSize(true);
} }
} catch (e) { } catch (e) {
logError(e, 'updating photoswipe after src url update failed'); if (e.message !== CustomError.URL_ALREADY_SET) {
logError(
e,
'updating photoswipe after src url update failed'
);
}
throw e; throw e;
} }
} catch (e) { } catch (e) {

View file

@ -19,6 +19,7 @@ import { FILE_TYPE } from 'constants/file';
import AlbumOutlined from '@mui/icons-material/AlbumOutlined'; import AlbumOutlined from '@mui/icons-material/AlbumOutlined';
import Avatar from './Avatar'; import Avatar from './Avatar';
import { shouldShowAvatar } from 'utils/file'; import { shouldShowAvatar } from 'utils/file';
import { CustomError } from '@ente/shared/error';
interface IProps { interface IProps {
file: EnteFile; file: EnteFile;
@ -259,7 +260,9 @@ export default function PreviewCard(props: IProps) {
setImgSrc(url); setImgSrc(url);
updateURL(file.id, url); updateURL(file.id, url);
} catch (e) { } catch (e) {
logError(e, 'preview card useEffect failed'); if (e.message !== CustomError.URL_ALREADY_SET) {
logError(e, 'preview card useEffect failed');
}
// no-op // no-op
} }
}; };

View file

@ -89,6 +89,9 @@ export const CustomError = {
MODEL_DOWNLOAD_PENDING: MODEL_DOWNLOAD_PENDING:
'Model download pending, skipping clip search request', 'Model download pending, skipping clip search request',
DOWNLOAD_MANAGER_NOT_READY: 'Download manager not initialized', DOWNLOAD_MANAGER_NOT_READY: 'Download manager not initialized',
UPDATE_URL_FILE_ID_MISMATCH: 'update url file id mismatch',
URL_ALREADY_SET: 'url already set',
FILE_CONVERSION_FAILED: 'file conversion failed',
}; };
export function handleUploadError(error: any): Error { export function handleUploadError(error: any): Error {