Skip to content

Commit 2837c41

Browse files
committed
factor out config error handling
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent 4954c73 commit 2837c41

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-32
lines changed

src/components/structures/ErrorView.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,29 @@ limitations under the License.
1717
import * as React from "react";
1818
import * as PropTypes from "prop-types";
1919

20+
import { _t } from "matrix-react-sdk/src/languageHandler";
21+
2022
interface IProps {
21-
title: React.ReactNode;
22-
message: React.ReactNode;
23+
title: string;
24+
messages?: string[];
2325
}
2426

25-
const ErrorView: React.FC<IProps> = ({title, message}) => {
27+
const ErrorView: React.FC<IProps> = ({title, messages}) => {
2628
return <div className="mx_GenericErrorPage">
2729
<div className="mx_GenericErrorPage_box">
28-
<h1>{ title }</h1>
29-
<p>{ message }</p>
30+
<h1>{title}</h1>
31+
<div>
32+
{messages && messages.map(msg => <p key={msg}>
33+
{ _t(msg) }
34+
</p>)}
35+
</div>
3036
</div>
3137
</div>;
3238
};
3339

3440
ErrorView.propTypes = {
35-
title: PropTypes.object.isRequired, // jsx for title
36-
message: PropTypes.object.isRequired, // jsx to display
41+
title: PropTypes.string.isRequired,
42+
messages: PropTypes.arrayOf(PropTypes.string.isRequired),
3743
};
3844

3945
export default ErrorView;

src/vector/index.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,28 @@ async function start() {
131131
preparePlatform();
132132
// load config requires the platform to be ready
133133
const loadConfigPromise = loadConfig();
134+
await settled(loadConfigPromise); // wait for it to settle
135+
// keep initialising so that we can show any possible error with as many features (theme, i18n) as possible
136+
137+
// Load language after loading config.json so that settingsDefaults.language can be applied
138+
const loadLanguagePromise = loadLanguage();
139+
// as quickly as we possibly can, set a default theme...
140+
const loadThemePromise = loadTheme();
141+
const loadSkinPromise = loadSkin();
142+
143+
// await things settling so that any errors we have to render have features like i18n running
144+
await settled(loadSkinPromise);
145+
await settled(loadThemePromise);
146+
await settled(loadLanguagePromise);
147+
148+
// ##########################
149+
// error handling begins here
150+
// ##########################
151+
if (!acceptBrowser) {
152+
await new Promise(resolve => {
153+
// todo
154+
});
155+
}
134156

135157
try {
136158
// await config here
@@ -146,33 +168,20 @@ async function start() {
146168
return showError(_t("Unable to load config file: please refresh the page to try again."));
147169
}
148170

149-
// Load language after loading config.json so that settingsDefaults.language can be applied
150-
const loadLanguagePromise = loadLanguage();
151-
// as quickly as we possibly can, set a default theme...
152-
const loadThemePromise = loadTheme();
153-
const loadSkinPromise = loadSkin();
154-
171+
// ##################################
172+
// app load critical path starts here
155173
// await things starting successfully
174+
// ##################################
156175
await loadOlmPromise;
157176
await settled(loadSkinPromise);
158177
await loadThemePromise;
159178
await loadLanguagePromise;
160179

161-
if (!acceptBrowser) {
162-
await new Promise(resolve => {
163-
// todo
164-
});
165-
}
166-
167180
// Finally, load the app. All of the other react-sdk imports are in this file which causes the skinner to
168181
// run on the components.
169182
await loadApp(fragparts.params, acceptBrowser);
170183
} catch (err) {
171184
console.trace(err);
172-
// check errors in this order:
173-
// Browser Compatibility (skippable)
174-
// config.json
175-
// runtime errors
176185
const { showError } = await import(
177186
/* webpackChunkName: "init" */
178187
/* webpackPreload: true */
@@ -181,6 +190,7 @@ async function start() {
181190
}
182191
}
183192
start().catch(err => {
193+
console.error(err);
184194
if (!acceptBrowser) {
185195
alert("Incompatible browser");
186196
}

src/vector/init.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,7 @@ export async function showError(title: string, messages?: string[]) {
150150
/* webpackChunkName: "error-view" */
151151
/* webpackPreload: true */
152152
"../components/structures/ErrorView")).default;
153-
const message = <div>
154-
{messages && messages.map(msg => <p key={msg}>
155-
{languageHandler._t(
156-
"Your Riot configuration contains invalid JSON. Please correct the problem and reload the page.",
157-
)}
158-
</p>)}
159-
</div>;
160-
161-
window.matrixChat = ReactDOM.render(<ErrorView title={title} message={message} />,
153+
window.matrixChat = ReactDOM.render(<ErrorView title={title} messages={messages} />,
162154
document.getElementById('matrixchat'));
163155
}
164156

0 commit comments

Comments
 (0)