Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

#21451 Fix WebGL disabled error message #10589

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/components/views/location/LocationPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,13 @@ class LocationPicker extends React.Component<ILocationPickerProps, IState> {
}
} catch (e) {
logger.error("Failed to render map", e);
const errorType =
(e as Error)?.message === LocationShareError.MapStyleUrlNotConfigured
? LocationShareError.MapStyleUrlNotConfigured
: LocationShareError.Default;
const errorMessage = (e as Error)?.message;
rashmitpankhania marked this conversation as resolved.
Show resolved Hide resolved
let errorType;
if (errorMessage === LocationShareError.MapStyleUrlNotConfigured)
errorType = LocationShareError.MapStyleUrlNotConfigured;
else if (errorMessage.includes("Failed to initialize WebGL"))
errorType = LocationShareError.WebGLNotEnabled;
else errorType = LocationShareError.Default;
this.setState({ error: errorType });
}
}
Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@
"No media permissions": "No media permissions",
"You may need to manually permit %(brand)s to access your microphone/webcam": "You may need to manually permit %(brand)s to access your microphone/webcam",
"This homeserver is not configured to display maps.": "This homeserver is not configured to display maps.",
"WebGL is required to display maps, please enable it in your browser settings.": "WebGL is required to display maps, please enable it in your browser settings.",
"This homeserver is not configured correctly to display maps, or the configured map server may be unreachable.": "This homeserver is not configured correctly to display maps, or the configured map server may be unreachable.",
"Toggle attribution": "Toggle attribution",
"Map feedback": "Map feedback",
Expand Down
3 changes: 3 additions & 0 deletions src/utils/location/LocationShareErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ import { _t } from "../../languageHandler";
export enum LocationShareError {
MapStyleUrlNotConfigured = "MapStyleUrlNotConfigured",
MapStyleUrlNotReachable = "MapStyleUrlNotReachable",
WebGLNotEnabled = "WebGLNotEnabled",
Default = "Default",
}

export const getLocationShareErrorMessage = (errorType?: LocationShareError): string => {
switch (errorType) {
case LocationShareError.MapStyleUrlNotConfigured:
return _t("This homeserver is not configured to display maps.");
case LocationShareError.WebGLNotEnabled:
return _t("WebGL is required to display maps, please enable it in your browser settings.");
case LocationShareError.MapStyleUrlNotReachable:
default:
return _t(
Expand Down
2 changes: 2 additions & 0 deletions src/utils/location/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export const createMap = (interactive: boolean, bodyId: string, onError?: (error
return map;
} catch (e) {
logger.error("Failed to render map", e);
const errorMessage = (e as Error)?.message;
if (errorMessage.includes("Failed to initialize WebGL")) throw new Error(LocationShareError.WebGLNotEnabled);
throw e;
}
};
Expand Down
14 changes: 14 additions & 0 deletions test/components/views/location/LocationPicker-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ describe("LocationPicker", () => {
expect(getByText("This homeserver is not configured to display maps.")).toBeInTheDocument();
});

it("displays error when WebGl is not enabled", () => {
// suppress expected error log
jest.spyOn(logger, "error").mockImplementation(() => {});
mocked(findMapStyleUrl).mockImplementation(() => {
throw new Error("Failed to initialize WebGL");
});

const { getByText } = getComponent();

expect(
getByText("WebGL is required to display maps, please enable it in your browser settings."),
).toBeInTheDocument();
});

it("displays error when map setup throws", () => {
// suppress expected error log
jest.spyOn(logger, "error").mockImplementation(() => {});
Expand Down