Skip to content

Commit 29d2eae

Browse files
authored
fix(schema-compiler): Yaml - crash on fully commented file (#6413)
1 parent 6518df4 commit 29d2eae

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

packages/cubejs-schema-compiler/src/compiler/YamlCompiler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export class YamlCompiler {
3131
}
3232

3333
const yamlObj = YAML.load(file.content);
34+
if (!yamlObj) {
35+
return;
36+
}
37+
3438
for (const key of Object.keys(yamlObj)) {
3539
if (key === 'cubes') {
3640
(yamlObj.cubes || []).forEach(({ name, ...cube }) => {

packages/cubejs-schema-compiler/test/unit/yaml-schema.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { prepareCompiler, prepareYamlCompiler } from './PrepareCompiler';
2-
import { createCubeSchema } from './utils';
1+
import { prepareYamlCompiler } from './PrepareCompiler';
32

43
describe('Yaml Schema Testing', () => {
54
it('members must be defined as arrays', async () => {
@@ -23,4 +22,20 @@ describe('Yaml Schema Testing', () => {
2322
expect(e.message).toContain('dimensions must be defined as array');
2423
}
2524
});
25+
26+
it('commented file crash', async () => {
27+
const { compiler } = prepareYamlCompiler(
28+
`
29+
#cubes:
30+
#- name: Products
31+
# sql: "select * from tbl"
32+
# dimensions:
33+
# name: Title
34+
# sql: name
35+
# type: string
36+
`
37+
);
38+
39+
await compiler.compile();
40+
});
2641
});

0 commit comments

Comments
 (0)