Skip to content
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/bruin/bruinConnections.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BruinCommandOptions } from "../types";
import { BruinCommand } from "./bruinCommand";
import { BruinPanel } from "../panels/BruinPanel";
import { extractNonNullConnections } from "../utilities/helperUtils";
import { extractNonNullConnections, friendlifyBruinError } from "../utilities/helperUtils";

/**
* Extends the BruinCommand class to implement the Bruin 'connections list' command.
Expand Down Expand Up @@ -58,7 +58,7 @@ export class BruinConnections extends BruinCommand {
} catch {
// If not JSON, use the original error
}
this.postMessageToPanels("error", errorMessage);
this.postMessageToPanels("error", friendlifyBruinError(errorMessage));
}
}
)
Expand Down
18 changes: 15 additions & 3 deletions src/bruin/bruinRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BruinPanel } from "../panels/BruinPanel";
import { BruinCommand } from "./bruinCommand";
import { BruinCommandOptions } from "../types";
import {
friendlifyBruinError,
isBruinAsset,
isBruinPipeline,
isBruinYaml,
Expand Down Expand Up @@ -116,12 +117,23 @@ export class BruinRender extends BruinCommand {
private parseError(error: unknown): string {
if (typeof error === 'object' && error !== null) {
const err = error as Error;
return JSON.stringify({ error: err.message });
return JSON.stringify({ error: friendlifyBruinError(err.message) });
}
if (typeof error === 'string') {
return error.startsWith("{") ? error : JSON.stringify({ error });
if (error.startsWith("{")) {
try {
const parsed = JSON.parse(error);
if (typeof parsed?.error === "string") {
return JSON.stringify({ ...parsed, error: friendlifyBruinError(parsed.error) });
}
} catch {
// fall through to wrapping the raw string
}
return error;
}
return JSON.stringify({ error: friendlifyBruinError(error) });
}
return JSON.stringify({ error: String(error) });
return JSON.stringify({ error: friendlifyBruinError(String(error)) });
}

private async isBruinPipeline(filePath: string): Promise<boolean> {
Expand Down
7 changes: 4 additions & 3 deletions src/bruin/bruinValidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BruinCommand } from "./bruinCommand";
import { BruinPanel } from "../panels/BruinPanel";
import { BruinCommandOptions } from "../types";
import { platform } from "os";
import { friendlifyBruinError } from "../utilities/helperUtils";
/**
* Extends the BruinCommand class to implement the bruin validate command on Bruin assets.
*/
Expand Down Expand Up @@ -100,17 +101,17 @@ export class BruinValidate extends BruinCommand {

// More comprehensive error handling
if (typeof error === "string") {
errorMessage = error;
errorMessage = friendlifyBruinError(error);
} else if (error instanceof Error) {
errorMessage = JSON.stringify({
error: error.message || "An unknown error occurred",
error: friendlifyBruinError(error.message || "An unknown error occurred"),
stack: error.stack,
});
} else if (typeof error === "object" && error !== null) {
try {
// Attempt to extract meaningful error information
errorMessage = JSON.stringify({
error: error.error || error.message || JSON.stringify(error),
error: friendlifyBruinError(error.error || error.message || JSON.stringify(error)),
});
} catch {
errorMessage = JSON.stringify({ error: "An unknown error occurred" });
Expand Down
44 changes: 44 additions & 0 deletions src/test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
prepareFlags,
cronToHumanReadable,
buildRenderFlags,
friendlifyBruinError,
FRIENDLY_NO_GIT_REPO_MESSAGE,
} from "../utilities/helperUtils";
import * as configuration from "../extension/configuration";
import * as bruinUtils from "../bruin/bruinUtils";
Expand Down Expand Up @@ -1092,6 +1094,48 @@ suite("Render Command Helper functions", () => {
const lineageString = { name: "example-name" };
assert.strictEqual(processLineageData(lineageString), "example-name");
});

suite("friendlifyBruinError", () => {
test("maps 'no git repository found' to the friendly message", () => {
assert.strictEqual(
friendlifyBruinError("no git repository found"),
FRIENDLY_NO_GIT_REPO_MESSAGE
);
});

test("maps 'failed to find the git repository root' to the friendly message", () => {
assert.strictEqual(
friendlifyBruinError("Failed to find the git repository root: no git repository found"),
FRIENDLY_NO_GIT_REPO_MESSAGE
);
});
Comment on lines +1106 to +1111
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Second pattern test doesn't isolate pattern 2

The string "Failed to find the git repository root: no git repository found" also satisfies the first pattern (/no git repository found/i), so this test would pass even if the second entry in NO_GIT_REPO_PATTERNS were removed. A string like "Failed to find the git repository root" (without the : no git repository found suffix) would uniquely exercise the second pattern.

Suggested change
test("maps 'failed to find the git repository root' to the friendly message", () => {
assert.strictEqual(
friendlifyBruinError("Failed to find the git repository root: no git repository found"),
FRIENDLY_NO_GIT_REPO_MESSAGE
);
});
test("maps 'failed to find the git repository root' to the friendly message", () => {
assert.strictEqual(
friendlifyBruinError("Failed to find the git repository root"),
FRIENDLY_NO_GIT_REPO_MESSAGE
);
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/test/extension.test.ts
Line: 1106-1111

Comment:
**Second pattern test doesn't isolate pattern 2**

The string `"Failed to find the git repository root: no git repository found"` also satisfies the first pattern (`/no git repository found/i`), so this test would pass even if the second entry in `NO_GIT_REPO_PATTERNS` were removed. A string like `"Failed to find the git repository root"` (without the `: no git repository found` suffix) would uniquely exercise the second pattern.

```suggestion
    test("maps 'failed to find the git repository root' to the friendly message", () => {
      assert.strictEqual(
        friendlifyBruinError("Failed to find the git repository root"),
        FRIENDLY_NO_GIT_REPO_MESSAGE
      );
    });
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


test("matches patterns case-insensitively", () => {
assert.strictEqual(
friendlifyBruinError("NO GIT REPOSITORY FOUND"),
FRIENDLY_NO_GIT_REPO_MESSAGE
);
});

test("passes through unrelated error strings unchanged", () => {
assert.strictEqual(
friendlifyBruinError("validation failed: syntax error at line 1"),
"validation failed: syntax error at line 1"
);
});

test("extracts message from Error instances", () => {
assert.strictEqual(
friendlifyBruinError(new Error("no git repository found")),
FRIENDLY_NO_GIT_REPO_MESSAGE
);
});

test("handles null/undefined safely", () => {
assert.strictEqual(friendlifyBruinError(null), "");
assert.strictEqual(friendlifyBruinError(undefined), "");
});
});
});

suite("BruinLineage Tests", () => {
Expand Down
18 changes: 18 additions & 0 deletions src/utilities/helperUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@ export const removeAnsiColors = (str: string): string => {
return str.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, "");
};

export const FRIENDLY_NO_GIT_REPO_MESSAGE =
"Bruin requires a git repository. Run `git init` at your project root, then reload the window.";

const NO_GIT_REPO_PATTERNS = [
/no git repository found/i,
/failed to find the git repository root/i,
];

export const friendlifyBruinError = (raw: unknown): string => {
const text =
typeof raw === "string"
? raw
: raw instanceof Error
? raw.message
: String(raw ?? "");
return NO_GIT_REPO_PATTERNS.some((re) => re.test(text)) ? FRIENDLY_NO_GIT_REPO_MESSAGE : text;
};

/* export const processLineageData =(lineageString : string): any => {
if (lineageString.startsWith('"') && lineageString.endsWith('"')) {
lineageString = lineageString.substring(1, lineageString.length - 1);
Expand Down
Loading