Skip to content

Commit 6a1b267

Browse files
committed
Suggest using sb3fix for zip corruption
1 parent 5542f58 commit 6a1b267

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/components/tw-invalid-project-modal/invalid-project-modal.jsx

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ const formatError = error => {
2222
return `${message}\n\n---\n\nURL: ${location.href}\nUser-Agent: ${navigator.userAgent}`;
2323
};
2424

25+
const errorMatches = (error, regex) => regex.test(`${error}`);
26+
27+
const isZipCorruptionWithSignatureIntact = error => (
28+
errorMatches(error, /Corrupted zip|uncompressed data size mismatch/) &&
29+
!errorMatches(error, /Corrupted zip: can't find zip signature/)
30+
);
31+
32+
const isJSONValidationError = error => errorMatches(error, /validationError/);
33+
2534
const InvalidProjectModal = props => (
2635
<Modal
2736
className={styles.modalContent}
@@ -47,7 +56,33 @@ const InvalidProjectModal = props => (
4756
value={formatError(props.error)}
4857
/>
4958

50-
{formatError(props.error).includes('validationError') && (
59+
{isZipCorruptionWithSignatureIntact(props.error) ? (
60+
<p>
61+
<FormattedMessage
62+
// eslint-disable-next-line max-len
63+
defaultMessage="This error often means that the file was corrupted, possibly due to a faulty storage device, power outage, or unplugging a USB drive without ejecting. Try {usingSb3fix} as it can fix this type of error."
64+
// eslint-disable-next-line max-len
65+
description="Part of modal that appears when a project could not be loaded. {usingSb3fix} becomes a link 'using sb3fix to recover your project'. sb3fix refers to https://turbowarp.github.io/sb3fix/"
66+
id="tw.invalidProject.zipCorruption"
67+
values={{
68+
usingSb3fix: (
69+
<a
70+
href="https://turbowarp.github.io/sb3fix/?platform=turbowarp"
71+
target="_blank"
72+
rel="noreferrer"
73+
>
74+
<FormattedMessage
75+
defaultMessage="using sb3fix to recover your project"
76+
// eslint-disable-next-line max-len
77+
description="Part of modal that appears when a project could not be loaded. Used in context 'Try using sb3fix to recover your project as it can fix this type of error'. sb3fix referes to https://turbowarp.github.io/sb3fix/"
78+
id="tw.invalidProject.sb3fix"
79+
/>
80+
</a>
81+
)
82+
}}
83+
/>
84+
</p>
85+
) : isJSONValidationError(props.error) ? (
5186
<p>
5287
<FormattedMessage
5388
// eslint-disable-next-line max-len
@@ -73,7 +108,7 @@ const InvalidProjectModal = props => (
73108
}}
74109
/>
75110
</p>
76-
)}
111+
) : null}
77112

78113
<p>
79114
<FormattedMessage

0 commit comments

Comments
 (0)