Skip to content

Commit

Permalink
Improve error handling for map files
Browse files Browse the repository at this point in the history
  • Loading branch information
spaaaacccee committed Feb 23, 2024
1 parent 23ca6f3 commit 862b755
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ function parseMesh({

const [, , counts, ...rest] = lines.filter(identity);

const [vertexCount] = counts.split(" ").map(parseInt);
const [vertexCount] = counts.split(/\s+/).map(parseInt);

const lines2 = rest.map((line) => line.split(" ").map(parseFloat));
const lines2 = rest.map((line) => line.split(/\s+/).map(parseFloat));

// 1-indexed vertices
const vertices = lines2.slice(0, vertexCount);
Expand Down
1 change: 1 addition & 0 deletions client/src/hooks/useParsedMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function useParsedMap(map?: Map, options?: Record<string, any>) {
} catch (e) {
console.error(e);
notify("Error parsing", get(e, "message"));
return { error: get(e, "message") };
}
}
}),
Expand Down
23 changes: 21 additions & 2 deletions client/src/layers/map/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CircularProgress } from "@mui/material";
import { CircularProgress, Typography } from "@mui/material";
import { MapPicker } from "components/app-bar/Input";
import { Heading, Option } from "components/layer-editor/Option";
import { getParser } from "components/renderer";
Expand All @@ -15,11 +15,12 @@ import { withProduce } from "produce";
import { useMemo } from "react";
import { Map } from "slices/UIState";
import { Layer, useLayer } from "slices/layers";
import { usePaper } from "theme";

export type MapLayerData = {
map?: Map;
options?: Record<string, any>;
parsedMap?: ParsedMap;
parsedMap?: ParsedMap & { error?: string };
};

export type MapLayer = Layer<MapLayerData>;
Expand All @@ -30,7 +31,9 @@ export const controller = {
layer?.source?.map
? `${layer.source.map.name} (${startCase(layer.source.map.format)})`
: "Untitled Map",
error: (layer) => layer?.source?.parsedMap?.error,
editor: withProduce(({ value, produce }) => {
const paper = usePaper();
const { result: Editor } = useMapOptions(value?.source?.map);
return (
<>
Expand All @@ -43,6 +46,22 @@ export const controller = {
/>
}
/>
{value?.source?.parsedMap?.error && (
<Typography
variant="body2"
color={(t) => t.palette.error.main}
sx={{
whiteSpace: "pre-line",
mb: 1,
mt: 1,
...paper(1),
p: 1,
borderRadius: 1,
}}
>
<code>{value?.source?.parsedMap?.error}</code>
</Typography>
)}
{!!value?.source?.map && (
<>
<Heading label="Map Options" />
Expand Down
12 changes: 12 additions & 0 deletions resources/maps/Small Mesh.mesh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mesh
3
5 4
0 0
0 10
10 10
10 0
5 5
0 3 4 1 5 -4 0 -2
1 3 1 2 5 -1 0 3
1 3 2 3 5 3 0 4
1 3 3 4 5 3 0 -1

0 comments on commit 862b755

Please sign in to comment.