Skip to content

Commit f653a11

Browse files
authored
chore: Update fixtures date (#4138)
## Description 1. What is this PR about (link the issue and add a short description) ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 45d9317 commit f653a11

File tree

31 files changed

+164
-132
lines changed

31 files changed

+164
-132
lines changed

.github/workflows/fixtures-test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ jobs:
5454
# This command will fail if there are uncommitted changes, i.e something has broken
5555
run: git diff --name-only HEAD --exit-code
5656

57-
- name: Show changed files
57+
- name: Show changed files and diff
5858
if: ${{ failure() }}
5959
run: |
6060
echo "Changed files are:"
6161
git diff --name-only HEAD
62+
git diff HEAD | head -n 1000

apps/builder/app/routes/rest.assets.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { createContext } from "~/shared/context.server";
1212
import env from "~/env/env.server";
1313
import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie";
1414
import { checkCsrf } from "~/services/csrf-session.server";
15+
import { parseError } from "~/shared/error/error-parse";
1516

1617
export const loader = async ({
1718
params,
@@ -55,11 +56,10 @@ export const action = async (props: ActionFunctionArgs) => {
5556
};
5657
}
5758
} catch (error) {
58-
if (error instanceof Error) {
59-
console.error({ error });
60-
return {
61-
errors: error.message,
62-
};
63-
}
59+
console.error(error);
60+
61+
return {
62+
errors: parseError(error).message,
63+
};
6464
}
6565
};

apps/builder/app/routes/rest.assets_.$name.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { createAssetClient } from "~/shared/asset-client";
77
import { createContext } from "~/shared/context.server";
88
import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie";
99
import { checkCsrf } from "~/services/csrf-session.server";
10+
import { parseError } from "~/shared/error/error-parse";
1011

1112
const UrlBody = z.object({
1213
url: z.string(),
@@ -68,11 +69,10 @@ export const action = async (
6869
};
6970
}
7071
} catch (error) {
71-
if (error instanceof Error) {
72-
console.error({ error });
73-
return {
74-
errors: error.message,
75-
};
76-
}
72+
console.error(error);
73+
74+
return {
75+
errors: parseError(error).message,
76+
};
7777
}
7878
};

apps/builder/app/routes/rest.build.$buildId.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { json, type LoaderFunctionArgs } from "@remix-run/server-runtime";
1+
import {
2+
json,
3+
type LoaderFunctionArgs,
4+
type TypedResponse,
5+
} from "@remix-run/server-runtime";
26
import type { Data } from "@webstudio-is/http-client";
37
import { db as projectDb } from "@webstudio-is/project/index.server";
48
import { loadProductionCanvasData } from "~/shared/db";
@@ -7,15 +11,17 @@ import { getUserById, type User } from "~/shared/db/user.server";
711
import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie";
812
import { allowedDestinations } from "~/services/destinations.server";
913
import { isDashboard } from "~/shared/router-utils";
14+
import { parseError } from "~/shared/error/error-parse";
1015

1116
export const loader = async ({
1217
params,
1318
request,
1419
}: LoaderFunctionArgs): Promise<
15-
Data & { user: { email: User["email"] } | undefined } & {
16-
projectDomain: string;
17-
projectTitle: string;
18-
}
20+
| (Data & { user: { email: User["email"] } | undefined } & {
21+
projectDomain: string;
22+
projectTitle: string;
23+
})
24+
| TypedResponse<{ error: string; message: string }>
1925
> => {
2026
if (false === isDashboard(request)) {
2127
throw new Response("Not Found", {
@@ -63,10 +69,10 @@ export const loader = async ({
6369
throw error;
6470
}
6571

66-
console.error({ error });
72+
console.error(error);
6773

6874
// We have no idea what happened, so we'll return a 500 error.
69-
throw json(error instanceof Error ? error.message : String(error), {
75+
throw json(parseError(error), {
7076
status: 500,
7177
});
7278
}

apps/builder/app/routes/rest.buildId.$projectId.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
import { json, type LoaderFunctionArgs } from "@remix-run/server-runtime";
1+
import {
2+
json,
3+
type LoaderFunctionArgs,
4+
type TypedResponse,
5+
} from "@remix-run/server-runtime";
26
import { db as projectDb } from "@webstudio-is/project/index.server";
37
import { allowedDestinations } from "~/services/destinations.server";
48
import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie";
59
import { createContext } from "~/shared/context.server";
10+
import { parseError } from "~/shared/error/error-parse";
611
import { isDashboard } from "~/shared/router-utils";
712

813
// This loader is only accessible from the dashboard origin
914
// and is used exclusively for the CLI.
1015
export const loader = async ({
1116
params,
1217
request,
13-
}: LoaderFunctionArgs): Promise<{ buildId: string | null }> => {
18+
}: LoaderFunctionArgs): Promise<
19+
{ buildId: string | null } | TypedResponse<{ error: string; message: string }>
20+
> => {
1421
if (false === isDashboard(request)) {
1522
throw new Response("Not Found", {
1623
status: 404,
@@ -46,10 +53,9 @@ export const loader = async ({
4653
throw error;
4754
}
4855

49-
console.error({ error });
56+
console.error(error);
5057

51-
// We have no idea what happened, so we'll return a 500 error.
52-
throw json(error instanceof Error ? error.message : String(error), {
58+
throw json(parseError(error), {
5359
status: 500,
5460
});
5561
}

apps/builder/app/shared/error/error-boundary.tsx

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,17 @@
1-
import { isRouteErrorResponse, useRouteError } from "@remix-run/react";
1+
import { useRouteError } from "@remix-run/react";
22
import { ClientOnly } from "../client-only";
33
import { lazy } from "react";
4-
import { z } from "zod";
4+
import { parseError } from "./error-parse";
55

66
const ErrorMessage = lazy(async () => {
77
const { ErrorMessage } = await import("./error-message.client");
88
return { default: ErrorMessage };
99
});
1010

11-
const PageError = z.union([
12-
z.string().transform((message) => ({ message, description: undefined })),
13-
z.object({
14-
message: z.string(),
15-
description: z.string().optional(),
16-
}),
17-
]);
18-
19-
const parseErrorObject = (
20-
error: unknown
21-
): {
22-
status: number;
23-
statusText?: string;
24-
message: string;
25-
description?: string;
26-
} => {
27-
if (error instanceof Error) {
28-
return {
29-
message: error.message,
30-
status: 500,
31-
};
32-
}
33-
34-
if (isRouteErrorResponse(error)) {
35-
const parsed = PageError.safeParse(error.data);
36-
37-
if (parsed.success) {
38-
return {
39-
message: parsed.data.message,
40-
description: parsed.data.description,
41-
status: error.status,
42-
statusText: error.statusText,
43-
};
44-
}
45-
46-
return {
47-
message: error.data ? JSON.stringify(error.data) : "unknown error",
48-
status: error.status,
49-
statusText: error.statusText,
50-
};
51-
}
52-
53-
const parsed = PageError.safeParse(error);
54-
if (parsed.success) {
55-
return {
56-
message: parsed.data.message,
57-
description: parsed.data.description,
58-
status: 1001,
59-
};
60-
}
61-
62-
return {
63-
message: JSON.stringify(error ?? "unknown error"),
64-
status: 1001,
65-
statusText: undefined,
66-
};
67-
};
68-
6911
export const ErrorBoundary = () => {
7012
const rawError = useRouteError();
7113

72-
const error = parseErrorObject(rawError);
14+
const error = parseError(rawError);
7315

7416
return (
7517
<ClientOnly>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { isRouteErrorResponse } from "@remix-run/react";
2+
import { z } from "zod";
3+
4+
// Currently, we have multiple error formats, and not all of them are covered here.
5+
// We should consolidate these formats into a single, unified format for consistency.
6+
const PageError = z.union([
7+
z.string().transform((message) => ({ message, description: undefined })),
8+
z
9+
.object({
10+
message: z.string(),
11+
details: z.string(),
12+
hint: z.string().nullable(),
13+
code: z.string(),
14+
})
15+
.transform(({ message, details, hint, code }) => ({
16+
message,
17+
description: `details: ${details}; hint: ${hint}; code: ${code}`,
18+
})),
19+
z.object({
20+
message: z.string(),
21+
description: z.string().optional(),
22+
}),
23+
]);
24+
25+
export const parseError = (
26+
error: unknown
27+
): {
28+
status: number;
29+
statusText?: string;
30+
message: string;
31+
description?: string;
32+
} => {
33+
if (error instanceof Error) {
34+
return {
35+
message: error.message,
36+
status: 500,
37+
};
38+
}
39+
40+
if (isRouteErrorResponse(error)) {
41+
const parsed = PageError.safeParse(error.data);
42+
43+
if (parsed.success) {
44+
return {
45+
message: parsed.data.message,
46+
description: parsed.data.description,
47+
status: error.status,
48+
statusText: error.statusText,
49+
};
50+
}
51+
52+
return {
53+
message: error.data ? JSON.stringify(error.data) : "unknown error",
54+
status: error.status,
55+
statusText: error.statusText,
56+
};
57+
}
58+
59+
const parsed = PageError.safeParse(error);
60+
if (parsed.success) {
61+
return {
62+
message: parsed.data.message,
63+
description: parsed.data.description,
64+
status: 1001,
65+
};
66+
}
67+
68+
return {
69+
message: JSON.stringify(error ?? "unknown error"),
70+
status: 1001,
71+
statusText: undefined,
72+
};
73+
};

fixtures/ssg-netlify-by-project-id/.webstudio/data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"id": "1e6d93b8-3faa-4155-8628-dd31cafaf00e",
44
"projectId": "8a7358b1-7de3-459d-b7b1-56dddfb6ce1e",
55
"version": 2,
6-
"createdAt": "2024-09-03T04:32:12.506",
6+
"createdAt": "2024-09-03T04:32:12.506+00:00",
77
"updatedAt": "2024-09-03T04:32:12.506+00:00",
88
"pages": {
99
"meta": {},

fixtures/ssg/.webstudio/data.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"id": "a2e8de30-03d5-4514-a3a6-406b3266a3af",
44
"projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",
55
"version": 38,
6-
"createdAt": "2024-07-29T12:50:07.515",
6+
"createdAt": "2024-07-29T12:50:07.515+00:00",
77
"updatedAt": "2024-07-29T12:50:07.515+00:00",
88
"pages": {
99
"meta": {
@@ -468,7 +468,7 @@
468468
"size": 999,
469469
"type": "image",
470470
"format": "svg",
471-
"createdAt": "2024-07-26T13:39:48.678",
471+
"createdAt": "2024-07-26T13:39:48.678+00:00",
472472
"meta": {
473473
"width": 14,
474474
"height": 16

fixtures/webstudio-cloudflare-template/.webstudio/data.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"id": "a2e8de30-03d5-4514-a3a6-406b3266a3af",
44
"projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",
55
"version": 38,
6-
"createdAt": "2024-07-29T12:50:07.515",
6+
"createdAt": "2024-07-29T12:50:07.515+00:00",
77
"updatedAt": "2024-07-29T12:50:07.515+00:00",
88
"pages": {
99
"meta": {
@@ -468,7 +468,7 @@
468468
"size": 999,
469469
"type": "image",
470470
"format": "svg",
471-
"createdAt": "2024-07-26T13:39:48.678",
471+
"createdAt": "2024-07-26T13:39:48.678+00:00",
472472
"meta": {
473473
"width": 14,
474474
"height": 16

0 commit comments

Comments
 (0)