From 342c885f525d987bc1a6c1096abb43a3e4ab2697 Mon Sep 17 00:00:00 2001 From: Nick Nalivaika Date: Sat, 14 Sep 2024 23:49:50 +0000 Subject: [PATCH] Improve error messages when workflow settings have non-string values for default project or dataset --- core/main_test.ts | 32 ++++++++++++++++++++++++++++++++ core/session.ts | 8 ++++++++ 2 files changed, 40 insertions(+) diff --git a/core/main_test.ts b/core/main_test.ts index e20842421..96c107966 100644 --- a/core/main_test.ts +++ b/core/main_test.ts @@ -468,6 +468,38 @@ someKey: and an extra: colon ); }); + test(`main fails when workflow settings have non-string default dataset`, () => { + const projectDir = tmpDirFixture.createNewTmpDir(); + fs.writeFileSync( + path.join(projectDir, "workflow_settings.yaml"), + ` +defaultProject: defaultProject +defaultDataset: 12345 +defaultLocation: US +` + ); + + expect(() => runMainInVm(coreExecutionRequestFromPath(projectDir))).to.throw( + "Default schema should be string." + ); + }); + + test(`main fails when workflow settings have non-string default project`, () => { + const projectDir = tmpDirFixture.createNewTmpDir(); + fs.writeFileSync( + path.join(projectDir, "workflow_settings.yaml"), + ` +defaultProject: 12345 +defaultDataset: defaultDataset +defaultLocation: US +` + ); + + expect(() => runMainInVm(coreExecutionRequestFromPath(projectDir))).to.throw( + "Default database should be string." + ); + }); + test(`main fails when a valid dataform.json contains unknown fields`, () => { const projectDir = tmpDirFixture.createNewTmpDir(); fs.writeFileSync( diff --git a/core/session.ts b/core/session.ts index cea1746b6..ec212db51 100644 --- a/core/session.ts +++ b/core/session.ts @@ -345,6 +345,14 @@ export class Session { ); } + if (typeof this.projectConfig.defaultDatabase !== "string") { + throw new Error("Default database should be string."); + } + + if (typeof this.projectConfig.defaultSchema !== "string") { + throw new Error("Default schema should be string."); + } + if ( !!this.projectConfig.vars && !Object.values(this.projectConfig.vars).every(value => typeof value === "string")