mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-29 10:20:59 -05:00
fix: catch errors from redux migration
This commit is contained in:
parent
028a8660c1
commit
064f223c78
3 changed files with 36 additions and 20 deletions
|
@ -5,6 +5,8 @@ import { ClientboundNotification } from "revolt.js/dist/websocket/notifications"
|
||||||
|
|
||||||
import { useEffect } from "preact/hooks";
|
import { useEffect } from "preact/hooks";
|
||||||
|
|
||||||
|
import { reportError } from "../../lib/ErrorBoundary";
|
||||||
|
|
||||||
import { useApplicationState } from "../../mobx/State";
|
import { useApplicationState } from "../../mobx/State";
|
||||||
|
|
||||||
import { useClient } from "./RevoltClient";
|
import { useClient } from "./RevoltClient";
|
||||||
|
@ -28,7 +30,11 @@ export default function SyncManager() {
|
||||||
if (!client) return;
|
if (!client) return;
|
||||||
function onPacket(packet: ClientboundNotification) {
|
function onPacket(packet: ClientboundNotification) {
|
||||||
if (packet.type === "UserSettingsUpdate") {
|
if (packet.type === "UserSettingsUpdate") {
|
||||||
|
try {
|
||||||
state.sync.apply(packet.update);
|
state.sync.apply(packet.update);
|
||||||
|
} catch (err) {
|
||||||
|
reportError(err, "failed_sync_apply");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,11 +27,7 @@ interface Props {
|
||||||
|
|
||||||
const ERROR_URL = "https://reporting.revolt.chat";
|
const ERROR_URL = "https://reporting.revolt.chat";
|
||||||
|
|
||||||
export default function ErrorBoundary({ children, section }: Props) {
|
export function reportError(error: Error, section: string) {
|
||||||
const [error, ignoreError] = useErrorBoundary();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (error) {
|
|
||||||
stackTrace.fromError(error).then((stackframes) =>
|
stackTrace.fromError(error).then((stackframes) =>
|
||||||
axios.post(ERROR_URL, {
|
axios.post(ERROR_URL, {
|
||||||
stackframes,
|
stackframes,
|
||||||
|
@ -43,6 +39,14 @@ export default function ErrorBoundary({ children, section }: Props) {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default function ErrorBoundary({ children, section }: Props) {
|
||||||
|
const [error, ignoreError] = useErrorBoundary();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (error) {
|
||||||
|
reportError(error, section);
|
||||||
|
}
|
||||||
}, [error]);
|
}, [error]);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
|
@ -4,6 +4,8 @@ import localforage from "localforage";
|
||||||
import { makeAutoObservable, reaction } from "mobx";
|
import { makeAutoObservable, reaction } from "mobx";
|
||||||
import { Client } from "revolt.js";
|
import { Client } from "revolt.js";
|
||||||
|
|
||||||
|
import { reportError } from "../lib/ErrorBoundary";
|
||||||
|
|
||||||
import { legacyMigrateForwards, LegacyState } from "./legacy/redux";
|
import { legacyMigrateForwards, LegacyState } from "./legacy/redux";
|
||||||
|
|
||||||
import Persistent from "./interfaces/Persistent";
|
import Persistent from "./interfaces/Persistent";
|
||||||
|
@ -197,17 +199,21 @@ export default class State {
|
||||||
*/
|
*/
|
||||||
async hydrate() {
|
async hydrate() {
|
||||||
// Migrate legacy Redux store.
|
// Migrate legacy Redux store.
|
||||||
|
try {
|
||||||
let legacy = await localforage.getItem("state");
|
let legacy = await localforage.getItem("state");
|
||||||
|
await localforage.removeItem("state");
|
||||||
if (legacy) {
|
if (legacy) {
|
||||||
if (typeof legacy === "string") {
|
if (typeof legacy === "string") {
|
||||||
legacy = JSON.parse(legacy);
|
legacy = JSON.parse(legacy);
|
||||||
}
|
}
|
||||||
|
|
||||||
legacyMigrateForwards(legacy as Partial<LegacyState>, this);
|
legacyMigrateForwards(legacy as Partial<LegacyState>, this);
|
||||||
await localforage.removeItem("state");
|
|
||||||
await this.save();
|
await this.save();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
reportError(err, "redux_migration");
|
||||||
|
}
|
||||||
|
|
||||||
// Load MobX store.
|
// Load MobX store.
|
||||||
const sync = (await localforage.getItem("sync")) as DataSync;
|
const sync = (await localforage.getItem("sync")) as DataSync;
|
||||||
|
|
Loading…
Reference in a new issue