fix: change error when section for item not found to logged warning and remove item (#2044)

This commit is contained in:
Meier Lukas
2025-01-22 18:18:14 +01:00
committed by GitHub
parent 29d4f9e003
commit b413e2ec7d
2 changed files with 8 additions and 6 deletions

View File

@@ -15,7 +15,7 @@ export const mapApp = (
boardSize: BoardSize, boardSize: BoardSize,
appsMap: Map<string, { id: string }>, appsMap: Map<string, { id: string }>,
sectionMap: Map<string, { id: string }>, sectionMap: Map<string, { id: string }>,
): InferInsertModel<typeof items> => { ): InferInsertModel<typeof items> | null => {
if (app.area.type === "sidebar") throw new Error("Mapping app in sidebar is not supported"); if (app.area.type === "sidebar") throw new Error("Mapping app in sidebar is not supported");
const shapeForSize = app.shape[boardSize]; const shapeForSize = app.shape[boardSize];
@@ -25,7 +25,8 @@ export const mapApp = (
const sectionId = sectionMap.get(app.area.properties.id)?.id; const sectionId = sectionMap.get(app.area.properties.id)?.id;
if (!sectionId) { if (!sectionId) {
throw new Error(`Failed to find section for app appId='${app.id}' sectionId='${app.area.properties.id}'`); logger.warn(`Failed to find section for app appId='${app.id}' sectionId='${app.area.properties.id}'. Removing app`);
return null;
} }
return { return {
@@ -69,9 +70,10 @@ export const mapWidget = (
const sectionId = sectionMap.get(widget.area.properties.id)?.id; const sectionId = sectionMap.get(widget.area.properties.id)?.id;
if (!sectionId) { if (!sectionId) {
throw new Error( logger.warn(
`Failed to find section for widget widgetId='${widget.id}' sectionId='${widget.area.properties.id}'`, `Failed to find section for widget widgetId='${widget.id}' sectionId='${widget.area.properties.id}'. Removing widget`,
); );
return null;
} }
return { return {

View File

@@ -10,5 +10,5 @@ export const prepareItems = (
) => ) =>
widgets widgets
.map((widget) => mapWidget(widget, boardSize, appsMap, sectionMap)) .map((widget) => mapWidget(widget, boardSize, appsMap, sectionMap))
.filter((widget) => widget !== null) .concat(apps.map((app) => mapApp(app, boardSize, appsMap, sectionMap)))
.concat(apps.map((app) => mapApp(app, boardSize, appsMap, sectionMap))); .filter((widget) => widget !== null);