Skip to content

Commit

Permalink
fix(schema-compiler): YAML - crash on unammed measure/dimension/join,…
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr authored Sep 18, 2023
1 parent 73f5ca7 commit 5c6a065
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/cubejs-schema-compiler/src/compiler/YamlCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,9 @@ export class YamlCompiler {
if (memberType === 'preAggregation' && indexes) {
indexes = this.yamlArrayToObj(indexes || [], `${memberType}.index`, errorsReport);
}

if (!name) {
errorsReport.error(`name isn't defined for ${memberType}: ${YAML.stringify(rest)}`);
errorsReport.error(`name isn't defined for ${memberType}: ${JSON.stringify(rest)}`);
return {};
} else if (indexes) {
return { [name]: { indexes, ...rest } };
Expand Down
21 changes: 21 additions & 0 deletions packages/cubejs-schema-compiler/test/unit/yaml-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,25 @@ describe('Yaml Schema Testing', () => {
expect(e.message).toContain('Unexpected input during yaml transpiling: null');
}
});

it('unammed measure', async () => {
const { compiler } = prepareYamlCompiler(
`cubes:
- name: Users
sql: SELECT * FROM e2e.users
dimensions:
- sql: id
type: number
primaryKey: true
`
);

try {
await compiler.compile();

throw new Error('compile must return an error');
} catch (e: any) {
expect(e.message).toContain('name isn\'t defined for dimension: ');
}
});
});

0 comments on commit 5c6a065

Please sign in to comment.