Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error messages when workflow settings have non-string values for default project or dataset #1846

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions core/main_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions core/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down