Skip to content

Commit

Permalink
Add 'run dbt compile' one-time logics
Browse files Browse the repository at this point in the history
  • Loading branch information
BAntonellini committed May 22, 2024
1 parent 46d3d0f commit 660b08e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
30 changes: 10 additions & 20 deletions src/features/helper/dbtInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ export interface DbtInterfaceErrorContainer {
};
}

const projectNotRegisteredError: DbtInterfaceErrorContainer = {
error: {
code: DbtInterfaceErrorCode.CompileSqlFailure,
message: "Sqlfluff currently unavailable. Check that your project does not contain compilation errors.",
data: {
"error": "",
},
},
};

export class DbtInterface {
private sql: string | undefined;
private sql_path: string | undefined;
Expand Down Expand Up @@ -116,16 +126,6 @@ export class DbtInterface {
},
};

const projectNotRegisteredError: DbtInterfaceErrorContainer = {
error: {
code: DbtInterfaceErrorCode.FailedToReachServer,
message: "Sqlfluff currently unavailable. Check that your project does not contain compilation errors.",
data: {
"error": "",
},
},
};

if (!await this.healthCheck()) {
Utilities.appendHyphenatedLine();
Utilities.outputChannel.appendLine("Unhealthy dbt project:");
Expand Down Expand Up @@ -173,16 +173,6 @@ export class DbtInterface {
},
};

const projectNotRegisteredError: DbtInterfaceErrorContainer = {
error: {
code: DbtInterfaceErrorCode.FailedToReachServer,
message: "Sqlfluff currently unavailable. Check that your project does not contain compilation errors.",
data: {
"error": "",
},
},
};

if (!await this.healthCheck()) {
Utilities.appendHyphenatedLine();
Utilities.outputChannel.appendLine("Unhealthy dbt project:");
Expand Down
37 changes: 27 additions & 10 deletions src/features/providers/sqlfluff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StringDecoder } from "string_decoder";
import * as vscode from "vscode";

import Configuration from "../helper/configuration";
import { DbtInterface } from "../helper/dbtInterface";
import { DbtInterface, DbtInterfaceErrorCode } from "../helper/dbtInterface";
import { LineDecoder } from "../helper/lineDecoder";
import Utilities from "../helper/utilities";
import FilePath from "./linter/types/filePath";
Expand All @@ -14,6 +14,7 @@ import CommandType from "./types/commandType";

export default class SQLFluff {
static childProcesses: CProcess.ChildProcess[] = [];
static shownDbtInterfacePopup: boolean = false;

public static async run(
workingDirectory: string | undefined,
Expand Down Expand Up @@ -59,16 +60,23 @@ export default class SQLFluff {
Utilities.outputChannel.appendLine(JSON.stringify(response, undefined, 2));
Utilities.appendHyphenatedLine();

return new Promise<CommandOutput>((resolve) => {
return new Promise<CommandOutput>(async (resolve) => {
const code = response?.error?.code ?? 0;
const succeeded = code === 0;
if (!succeeded && !Configuration.suppressNotifications()) {
if (!succeeded && !Configuration.suppressNotifications() && !this.shownDbtInterfacePopup) {
const message = response?.error?.message ?? "DBT-Interface formatting error.";
const detail = response?.error?.data?.error ?? "";

vscode.window.showErrorMessage([message, detail].join("\n"));
if (code === DbtInterfaceErrorCode.CompileSqlFailure) {
this.shownDbtInterfacePopup = true;
const runDbt = "Debug by running dbt Compile";
const chosen = await vscode.window.showErrorMessage(message, runDbt)
if (chosen === runDbt) {
await vscode.commands.executeCommand("dbtPowerUser.dbtCompile");
}
} else {
vscode.window.showErrorMessage([message, detail].join("\n"));
}
}

resolve({
// 0 = all good, 1 = format passed but contains unfixable linting violations, 65 = lint passed but found errors
succeeded: succeeded,
Expand Down Expand Up @@ -131,19 +139,28 @@ export default class SQLFluff {
},
];

Utilities.outputChannel.appendLine("Raw dbt-omsosis /lint output:");
Utilities.outputChannel.appendLine("Raw dbt-core-interface /lint output:");
Utilities.appendHyphenatedLine();
Utilities.outputChannel.appendLine(JSON.stringify(response, undefined, 2));
Utilities.appendHyphenatedLine();

return new Promise<CommandOutput>((resolve) => {
return new Promise<CommandOutput>(async (resolve) => {
const code = response?.error?.code ?? 0;
const succeeded = code === 0;
if (!succeeded && !Configuration.suppressNotifications()) {
if (!succeeded && !Configuration.suppressNotifications() && !this.shownDbtInterfacePopup) {
const message = response?.error?.message ?? "DBT-Interface linting error.";
const detail = response?.error?.data?.error ?? "";

vscode.window.showErrorMessage([message, detail].join("\n"));
if (code === DbtInterfaceErrorCode.CompileSqlFailure) {
this.shownDbtInterfacePopup = true;
const runDbt = "Debug by running dbt Compile";
const chosen = await vscode.window.showErrorMessage(message, runDbt)
if (chosen === runDbt) {
await vscode.commands.executeCommand("dbtPowerUser.dbtCompile");
}
} else {
vscode.window.showErrorMessage([message, detail].join("\n"));
}
}

resolve({
Expand Down

0 comments on commit 660b08e

Please sign in to comment.