Skip to content

Better zod errors #4681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2025
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
4 changes: 2 additions & 2 deletions gui/src/pages/config-error/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
} from "@heroicons/react/24/outline";
import { useNavigate } from "react-router-dom";
import { vscBackground } from "../../components";
import { ROUTES } from "../../util/navigation";
import { useAppSelector } from "../../redux/hooks";
import { ROUTES } from "../../util/navigation";

export default function ConfigErrorPage() {
const navigate = useNavigate();
Expand Down Expand Up @@ -52,7 +52,7 @@ export default function ConfigErrorPage() {
) : (
<ExclamationTriangleIcon className="mr-2 h-5 w-5" />
)}
<p className="m-0">
<p className="m-0 whitespace-pre-wrap">
<strong>
{error.fatal ? "Fatal Error:" : "Warning:"}
</strong>{" "}
Expand Down
19 changes: 14 additions & 5 deletions packages/config-yaml/src/load/unroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ import { useProxyForUnrenderedSecrets } from "./clientRender.js";
export function parseConfigYaml(configYaml: string): ConfigYaml {
try {
const parsed = YAML.parse(configYaml);
const result = configYamlSchema.parse(parsed);
return result;
} catch (e: any) {
console.log(configYaml);
throw new Error(`Failed to parse rolled assistant: ${e.message}`);
const result = configYamlSchema.safeParse(parsed);
if (result.success) {
return result.data;
}
throw new Error(
result.error.errors
.map((e) => `${e.path.join(".")}: ${e.message}`)
.join(""),
);
} catch (e) {
console.log("Failed to parse rolled assistant:", configYaml);
throw new Error(
`Failed to parse assistant:\n${e instanceof Error ? e.message : e}`,
);
}
}

Expand Down
Loading