Skip to content

feat: better YAML parsing error reporting #5750

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"winston": "^3.17.0",
"workerpool": "^9.1.3",
"yaml": "^2.4.2",
"zod": "^3.24.2"
"zod": "^3.25.13"
},
"engine-strict": true,
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion extensions/vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions gui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions packages/config-yaml/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/config-yaml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"dependencies": {
"@continuedev/config-types": "^1.0.14",
"yaml": "^2.6.1",
"zod": "^3.24.2"
"zod": "^3.25.13",
"zod-validation-error": "^3.4.1"
},
"devDependencies": {
"@types/jest": "^29.5.14",
Expand Down
72 changes: 72 additions & 0 deletions packages/config-yaml/src/load/unroll.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { configYamlSchema } from "../schemas/index.js";
import { parseConfigYaml } from "./unroll.js";



describe("config.yaml validation", () => {
it("parses valid config YAML", () => {
const yaml = `
name: Local Assistant
version: 1.0.0
schema: v1

models:
- name: granite3.3:8b
provider: ollama
model: granite3.3:8b
roles:
- autocomplete
- chat

- name: nomic-embed-text
provider: ollama
model: nomic-embed-text:latest
roles:
- embed

context:
- provider: code
- provider: docs
- provider: diff
- provider: terminal
- provider: problems
- provider: folder
- provider: codebase
- provider: clipboard

rules:
- name: Angry Teenager
rule: always respond like an angry teenager

docs:
- name: Continue docs
startUrl: https://docs.continue.dev/
`;
const result = parseConfigYaml(yaml);
expect(result).toMatchObject({ name: "Local Assistant", version: "1.0.0" });
expect(() => configYamlSchema.parse(result)).not.toThrow();
});

it("throws on invalid YAML", () => {
const yaml = `
name: Local Assistant
version: 1.0.0
schema: v1

models: []

context:
- provider: code
- provider: codebase

data:
- destination: https://docs.continue.dev/
`;

const expectedError = `Failed to parse assistant:
Validation error: Required at \"data[0].name\"; Required at \"data[0].schema\", or Required at \"data[0].uses\"`;

expect(() => parseConfigYaml(yaml)).toThrow(expectedError);
});

});
11 changes: 4 additions & 7 deletions packages/config-yaml/src/load/unroll.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as YAML from "yaml";
import { fromError } from "zod-validation-error";
import { PlatformClient, Registry } from "../interfaces/index.js";
import { encodeSecretLocation } from "../interfaces/SecretResult.js";
import {
Expand Down Expand Up @@ -30,13 +31,9 @@ export function parseConfigYaml(configYaml: string): ConfigYaml {
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 fromError(result.error);
} catch (e : any) {
console.log("Failed to parse rolled assistant:", configYaml, e.message);
throw new Error(
`Failed to parse assistant:\n${e instanceof Error ? e.message : e}`,
);
Expand Down
Loading