Skip to content

Commit 3cdd7ca

Browse files
fix: do not throw but provide errors (#1002)
1 parent 36bb441 commit 3cdd7ca

4 files changed

Lines changed: 88 additions & 16 deletions

File tree

package-lock.json

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

packages/helix-shared-config/src/IndexConfig.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,11 @@ export class IndexConfig extends SchemaDerivedConfig {
195195
}
196196

197197
/**
198-
* Validates the loaded configuration and coerces types and sets defaulst
198+
* Return errors encountered in parsing.
199+
*
200+
* @returns {String[]} parsing errors
199201
*/
200-
async validate() {
201-
await super.validate();
202-
203-
if (this._document?.errors?.length) {
204-
const detail = this._document.errors.map(({ message }) => (message)).join('\n');
205-
throw new Error(`Invalid index configuration:
206-
${detail}`);
207-
}
202+
getErrors() {
203+
return this._document?.errors ?? [];
208204
}
209205
}

packages/helix-shared-config/test/IndexConfig.test.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,28 @@ describe('Index Config Loading', () => {
7272
assert.deepEqual(actual, expected);
7373
});
7474

75-
it('Trips over broken config', async () => {
75+
it('Does not trip over broken config', async () => {
7676
const cfg = new IndexConfig()
7777
.withConfigPath(path.resolve(SPEC_ROOT, 'broken.yaml'));
7878

79-
await assert.rejects(async () => cfg.init(), /Implicit map keys need to be followed by map value/);
79+
await cfg.init();
80+
81+
assert.strictEqual(cfg.getQuery('foo', 'bar'), undefined);
82+
83+
const actual = cfg.toJSON();
84+
const expected = JSON.parse(await fs.readFile(path.resolve(SPEC_ROOT, 'broken.json'), 'utf-8'));
85+
86+
assert.deepEqual(actual, expected);
8087
});
8188

82-
it('Trips over config with duplicate property', async () => {
89+
it('Parsed config contains errors', async () => {
8390
const cfg = new IndexConfig()
8491
.withConfigPath(path.resolve(SPEC_ROOT, 'duplicate.yaml'));
8592

86-
await assert.rejects(async () => cfg.init(), /Map keys must be unique at line 10, column 7/);
93+
await cfg.init();
94+
95+
const details = cfg.getErrors().map(({ message }) => (message)).join('\n');
96+
assert.match(details, /Map keys must be unique at line 10, column 7/);
8797
});
8898

8999
it('Does not trip over non-existing config', async () => {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"indices": {
3+
"blog-posts": {
4+
"fetch": "https://${repo}-${owner}.project-helix.page/${path}",
5+
"properties": {
6+
"author": {
7+
"faceted": true,
8+
"select": "main > div:nth-of-type(3) > p:nth-of-type(1)",
9+
"value": "${match('by (.*)')}\n"
10+
}
11+
},
12+
"source": "html"
13+
}
14+
},
15+
"version": "1",
16+
"​": null
17+
}

0 commit comments

Comments
 (0)