mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Handle cloud project opening errors better (#5202)
Don't show in changelog
This commit is contained in:
@@ -855,7 +855,6 @@ const MainFrame = (props: Props) => {
|
||||
const openFromFileMetadata = React.useCallback(
|
||||
async (fileMetadata: FileMetadata): Promise<?State> => {
|
||||
const storageProviderOperations = getStorageProviderOperations();
|
||||
const storageProviderInternalName = getStorageProvider().internalName;
|
||||
|
||||
const {
|
||||
hasAutoSave,
|
||||
@@ -916,6 +915,7 @@ const MainFrame = (props: Props) => {
|
||||
await delay(150);
|
||||
const autoSaveFileMetadata = await checkForAutosave();
|
||||
let content;
|
||||
let openingError: Error | null = null;
|
||||
try {
|
||||
const result = await onOpen(
|
||||
autoSaveFileMetadata,
|
||||
@@ -923,6 +923,7 @@ const MainFrame = (props: Props) => {
|
||||
);
|
||||
content = result.content;
|
||||
} catch (error) {
|
||||
openingError = error;
|
||||
// onOpen failed, try to find again an autosave.
|
||||
const autoSaveAfterFailureFileMetadata = await checkForAutosaveAfterFailure();
|
||||
if (autoSaveAfterFailureFileMetadata) {
|
||||
@@ -931,9 +932,10 @@ const MainFrame = (props: Props) => {
|
||||
}
|
||||
}
|
||||
if (!content) {
|
||||
throw new Error(
|
||||
'The project file content could not be read. It might be corrupted/malformed.'
|
||||
);
|
||||
throw openingError ||
|
||||
new Error(
|
||||
'The project file content could not be read. It might be corrupted/malformed.'
|
||||
);
|
||||
}
|
||||
if (!verifyProjectContent(i18n, content)) {
|
||||
// The content is not recognized and the user was warned. Abort the opening.
|
||||
@@ -957,7 +959,7 @@ const MainFrame = (props: Props) => {
|
||||
serializedProject.delete();
|
||||
}
|
||||
} catch (error) {
|
||||
if (storageProviderInternalName === 'Cloud') {
|
||||
if (error.name === 'CloudProjectReadingError') {
|
||||
setIsLoadingProject(false);
|
||||
setLoaderModalProgress(null, null);
|
||||
setCloudProjectFileMetadataToRecover(fileMetadata);
|
||||
@@ -979,7 +981,6 @@ const MainFrame = (props: Props) => {
|
||||
[
|
||||
i18n,
|
||||
getStorageProviderOperations,
|
||||
getStorageProvider,
|
||||
loadFromSerializedProject,
|
||||
showConfirmation,
|
||||
showAlert,
|
||||
|
@@ -11,6 +11,18 @@ import { type AuthenticatedUser } from '../../Profile/AuthenticatedUserContext';
|
||||
import { type FileMetadata } from '..';
|
||||
import { unzipFirstEntryOfBlob } from '../../Utils/Zip.js/Utils';
|
||||
|
||||
class CloudProjectReadingError extends Error {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, CloudProjectReadingError);
|
||||
}
|
||||
|
||||
this.name = 'CloudProjectReadingError';
|
||||
}
|
||||
}
|
||||
|
||||
export const generateOnOpen = (authenticatedUser: AuthenticatedUser) => async (
|
||||
fileMetadata: FileMetadata,
|
||||
onProgress?: (progress: number, message: MessageDescriptor) => void
|
||||
@@ -32,13 +44,16 @@ export const generateOnOpen = (authenticatedUser: AuthenticatedUser) => async (
|
||||
);
|
||||
onProgress && onProgress((4 / 4) * 100, t`Opening portal`);
|
||||
// Reading only the first entry since the zip should only contain the project json file
|
||||
const serializedProject = await unzipFirstEntryOfBlob(
|
||||
zippedSerializedProject
|
||||
);
|
||||
|
||||
return {
|
||||
content: JSON.parse(serializedProject),
|
||||
};
|
||||
try {
|
||||
const serializedProject = await unzipFirstEntryOfBlob(
|
||||
zippedSerializedProject
|
||||
);
|
||||
return {
|
||||
content: JSON.parse(serializedProject),
|
||||
};
|
||||
} catch (error) {
|
||||
throw new CloudProjectReadingError();
|
||||
}
|
||||
};
|
||||
|
||||
export const generateOnEnsureCanAccessResources = (
|
||||
|
@@ -106,8 +106,8 @@ export const isCloudProjectVersionSane = async (
|
||||
{ responseType: 'blob' }
|
||||
)
|
||||
);
|
||||
const projectFile = await unzipFirstEntryOfBlob(response.data);
|
||||
try {
|
||||
const projectFile = await unzipFirstEntryOfBlob(response.data);
|
||||
JSON.parse(projectFile);
|
||||
return true;
|
||||
} catch (error) {
|
||||
|
Reference in New Issue
Block a user