feat(integration): improve integration test connection (#3005)

This commit is contained in:
Meier Lukas
2025-05-16 20:59:12 +02:00
committed by GitHub
parent 3daf1c8341
commit ef9a5e9895
111 changed files with 7168 additions and 976 deletions

View File

@@ -0,0 +1,3 @@
export * from "./parse-error-handler";
export * from "./zod-parse-error-handler";
export * from "./json-parse-error-handler";

View File

@@ -0,0 +1,16 @@
import { logger } from "@homarr/log";
import { ParseError } from "../parse-error";
import { ParseErrorHandler } from "./parse-error-handler";
export class JsonParseErrorHandler extends ParseErrorHandler {
handleParseError(error: unknown): ParseError | undefined {
if (!(error instanceof SyntaxError)) return undefined;
logger.debug("Received JSON parse error", {
message: error.message,
});
return new ParseError("Failed to parse json", { cause: error });
}
}

View File

@@ -0,0 +1,5 @@
import type { ParseError } from "../parse-error";
export abstract class ParseErrorHandler {
abstract handleParseError(error: unknown): ParseError | undefined;
}

View File

@@ -0,0 +1,24 @@
import { ZodError } from "zod";
import { fromError } from "zod-validation-error";
import { logger } from "@homarr/log";
import { ParseError } from "../parse-error";
import { ParseErrorHandler } from "./parse-error-handler";
export class ZodParseErrorHandler extends ParseErrorHandler {
handleParseError(error: unknown): ParseError | undefined {
if (!(error instanceof ZodError)) return undefined;
// TODO: migrate to zod v4 prettfyError once it's released
// https://v4.zod.dev/v4#error-pretty-printing
const message = fromError(error, {
issueSeparator: "\n",
prefix: null,
}).toString();
logger.debug("Received Zod parse error");
return new ParseError(message, { cause: error });
}
}

View File

@@ -0,0 +1,2 @@
export * from "./handlers";
export * from "./parse-error";

View File

@@ -0,0 +1,10 @@
export class ParseError extends Error {
constructor(message: string, options?: { cause: Error }) {
super(`Failed to parse data:\n${message}`, options);
this.name = ParseError.name;
}
get cause(): Error {
return super.cause as Error;
}
}