Skip to content

Commit

Permalink
feat: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
AdiGajbhiye committed Feb 1, 2024
1 parent d772d61 commit b386fe4
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 4 deletions.
62 changes: 58 additions & 4 deletions src/dbt_client/dbtTerminal.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { EventEmitter, Terminal, window } from "vscode";
import { provideSingleton, stripANSI } from "../utils";
import { Disposable, EventEmitter, Terminal, window } from "vscode";
import {
extendErrorWithSupportLinks,
provideSingleton,
stripANSI,
} from "../utils";
import { CustomException } from "./exception";
import { TelemetryService } from "../telemetry";

@provideSingleton(DBTTerminal)
export class DBTTerminal {
private disposables: Disposable[] = [];
private terminal?: Terminal;
private readonly writeEmitter = new EventEmitter<string>();
private outputChannel = window.createOutputChannel(`Log - dbt`);
private outputChannel = window.createOutputChannel(`Log - dbt`, {
log: true,
});

constructor(private telemetry: TelemetryService) {}

show(status: boolean) {
if (status) {
Expand All @@ -15,12 +26,55 @@ export class DBTTerminal {
}

log(message: string) {
this.outputChannel.append(stripANSI(message));
this.outputChannel.info(stripANSI(message));
if (this.terminal !== undefined) {
this.writeEmitter.fire(message);
}
}

trace(message: string) {
this.outputChannel?.appendLine(stripANSI(message));
console.log(message);
}

debug(message: string) {
this.outputChannel?.debug(stripANSI(message));
console.debug(message);
}

info(name: string, message: string, sendTelemetry: boolean = true) {
this.outputChannel?.info(stripANSI(message));
console.info(`${name}:${message}`);
if (sendTelemetry) {
this.telemetry.sendTelemetryEvent(name, { message });
}
}

warn(e: CustomException, sendTelemetry: boolean = true) {
const message = e.getMessage();
this.outputChannel?.warn(stripANSI(message));
console.warn(`${e.name}:${message}`);
if (sendTelemetry) {
this.telemetry.sendTelemetryError(e.name, e.error, { message });
}
}

error(e: CustomException, sendTelemetry = true) {
const message = e.getMessage();
this.outputChannel?.error(stripANSI(message));
console.error(`${e.name}:${message}`);
if (sendTelemetry) {
this.telemetry.sendTelemetryError(e.name, e.error, { message });
}
}

dispose() {
while (this.disposables.length) {
const x = this.disposables.pop();
x?.dispose();
}
}

private requireTerminal() {
if (this.terminal === undefined) {
this.terminal = window.createTerminal({
Expand Down
39 changes: 39 additions & 0 deletions src/dbt_client/exception.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { PythonException } from "python-bridge";

export abstract class CustomException {
constructor(
public name: string,
public error?: Error | unknown,
) {}

abstract getMessage(): string;
}

export class CustomPythonException extends CustomException {
constructor(
public name: string,
public error: PythonException,
) {
super(name, error);
}

getMessage(): string {
return this.error.exception.message;
}
}

export class CustomUnknownException extends CustomException {
constructor(
public name: string,
public error: unknown,
) {
super(name, error);
}

getMessage(): string {
if (this.error && this.error instanceof Error) {
return this.error.message;
}
return `${this.error}`;
}
}

0 comments on commit b386fe4

Please sign in to comment.