Skip to content

Commit b6835fb

Browse files
committed
feat: better YAML parsing error reporting
Signed-off-by: Fred Bricon <[email protected]>
1 parent f692fe0 commit b6835fb

File tree

8 files changed

+109
-21
lines changed

8 files changed

+109
-21
lines changed

core/package-lock.json

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"winston": "^3.17.0",
112112
"workerpool": "^9.1.3",
113113
"yaml": "^2.4.2",
114-
"zod": "^3.24.2"
114+
"zod": "^3.25.13"
115115
},
116116
"engine-strict": true,
117117
"engines": {

extensions/vscode/package-lock.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gui/package-lock.json

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/config-yaml/package-lock.json

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/config-yaml/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"dependencies": {
1919
"@continuedev/config-types": "^1.0.14",
2020
"yaml": "^2.6.1",
21-
"zod": "^3.24.2"
21+
"zod": "^3.25.13",
22+
"zod-validation-error": "^3.4.1"
2223
},
2324
"devDependencies": {
2425
"@types/jest": "^29.5.14",
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { configYamlSchema } from "../schemas/index.js";
2+
import { parseConfigYaml } from "./unroll.js";
3+
4+
5+
6+
describe("config.yaml validation", () => {
7+
it("parses valid config YAML", () => {
8+
const yaml = `
9+
name: Local Assistant
10+
version: 1.0.0
11+
schema: v1
12+
13+
models:
14+
- name: granite3.3:8b
15+
provider: ollama
16+
model: granite3.3:8b
17+
roles:
18+
- autocomplete
19+
- chat
20+
21+
- name: nomic-embed-text
22+
provider: ollama
23+
model: nomic-embed-text:latest
24+
roles:
25+
- embed
26+
27+
context:
28+
- provider: code
29+
- provider: docs
30+
- provider: diff
31+
- provider: terminal
32+
- provider: problems
33+
- provider: folder
34+
- provider: codebase
35+
- provider: clipboard
36+
37+
rules:
38+
- name: Angry Teenager
39+
rule: always respond like an angry teenager
40+
41+
docs:
42+
- name: Continue docs
43+
startUrl: https://docs.continue.dev/
44+
`;
45+
const result = parseConfigYaml(yaml);
46+
expect(result).toMatchObject({ name: "Local Assistant", version: "1.0.0" });
47+
expect(() => configYamlSchema.parse(result)).not.toThrow();
48+
});
49+
50+
it("throws on invalid YAML", () => {
51+
const yaml = `
52+
name: Local Assistant
53+
version: 1.0.0
54+
schema: v1
55+
56+
models: []
57+
58+
context:
59+
- provider: code
60+
- provider: codebase
61+
62+
data:
63+
- destination: https://docs.continue.dev/
64+
`;
65+
66+
const expectedError = `Failed to parse assistant:
67+
Validation error: Required at \"data[0].name\"; Required at \"data[0].schema\", or Required at \"data[0].uses\"`;
68+
69+
expect(() => parseConfigYaml(yaml)).toThrow(expectedError);
70+
});
71+
72+
});

packages/config-yaml/src/load/unroll.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as YAML from "yaml";
2+
import { fromError } from "zod-validation-error";
23
import { PlatformClient, Registry } from "../interfaces/index.js";
34
import { encodeSecretLocation } from "../interfaces/SecretResult.js";
45
import {
@@ -30,13 +31,9 @@ export function parseConfigYaml(configYaml: string): ConfigYaml {
3031
if (result.success) {
3132
return result.data;
3233
}
33-
throw new Error(
34-
result.error.errors
35-
.map((e) => `${e.path.join(".")}: ${e.message}`)
36-
.join(""),
37-
);
38-
} catch (e) {
39-
console.log("Failed to parse rolled assistant:", configYaml);
34+
throw fromError(result.error);
35+
} catch (e : any) {
36+
console.log("Failed to parse rolled assistant:", configYaml, e.message);
4037
throw new Error(
4138
`Failed to parse assistant:\n${e instanceof Error ? e.message : e}`,
4239
);

0 commit comments

Comments
 (0)