Skip to content
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.3.5] - 2026-11-19

### Added

- **MongoDB Local & Docker Discovery:**
- Automated local MongoDB socket and wire-protocol discovery (`localhost:27017` / `127.0.0.1:27017`).
- Automated Docker container discovery inspecting running containers (`mongo`, `mongodb`, `percona`, `bitnami`) with mapped host ports.
- One-click connection prefilling via the frontend `useDiscoveredDatabases` hook and discovered connections dashboard card.
- **Tree-Shaken Database Icons:**
- Migrated PostgreSQL, MySQL, MariaDB, SQLite, DuckDB, ClickHouse, and MongoDB iconography to `react-devicons`.
- Dropped external Devicon CDN stylesheet from `index.html`, eliminating render-blocking network dependencies.

### Changed

- **Enhanced What's New Dialog:**
- Expanded modal layout to `max-w-4xl` and `max-h-[85vh]` for desktop reading comfort.
- Added comprehensive GitHub Flavored Markdown (GFM) styling for headers, lists, code syntax highlighting, markdown tables, and blockquotes.
- Added localStorage release notes caching with fallback rendering.
- **Welcome View Navigation & Scrolling:**
- Integrated `ScrollArea` into the "Total Tables" sheet to resolve content truncation and ensure fluid vertical scrolling.

### Fixed

- **Graceful Offline Database Handling:**
- Added `isOfflineError` classifier across bridge database handlers (`db.listTables`, `db.listSchemas`, `db.getStats`, `db.connect`), returning structured `{ isOffline: true }` responses and logging warnings instead of throwing disruptive `IO_ERROR` exceptions to the webview.
- Refined error classification to require connection-specific indicators, preventing SQL identifiers (e.g. `offline_orders`) or MySQL permission errors from triggering false offline states.
- Added recursive `err.cause` unwrapping for wrapped driver exceptions.
- **Connection Status Lifecycle & Pending State Isolation:**
- Separated initial pending connection checks (`isPending: true`) from confirmed offline results in `WelcomeView`.
- Displayed checking status indicators during cold startup to eliminate false "Offline" flickers.
- Propagated top-level `isOffline` flag through `getDataBaseStats` and `ConnectionSizeItem`, correctly distinguishing genuine zero statistics (`0.00 MB`) from unavailable offline statistics (`Offline`).

## [1.3.0] - 2026-11-17

### Added
Expand Down
203 changes: 203 additions & 0 deletions bridge/__tests__/databaseOffline.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
import { describe, expect, test, jest } from "@jest/globals";
import { isOfflineError } from "../src/services/databaseService";
import { DatabaseHandlers } from "../src/handlers/databaseHandlers";
import { StatsHandlers } from "../src/handlers/statsHandlers";

describe("isOfflineError helper", () => {
test("identifies standard Node network error codes as offline", () => {
expect(isOfflineError({ code: "ENOTFOUND" })).toBe(true);
expect(isOfflineError({ code: "ECONNREFUSED" })).toBe(true);
expect(isOfflineError({ code: "ETIMEDOUT" })).toBe(true);
expect(isOfflineError({ code: "EHOSTUNREACH" })).toBe(true);
expect(isOfflineError({ code: "ENETUNREACH" })).toBe(true);
expect(isOfflineError({ code: "ECONNRESET" })).toBe(true);
expect(isOfflineError({ code: "EAI_AGAIN" })).toBe(true);
expect(isOfflineError({ code: "EPIPE" })).toBe(true);
expect(isOfflineError({ code: "PROTOCOL_CONNECTION_LOST" })).toBe(true);
});

test("identifies MongoDB driver network/topology error names as offline", () => {
expect(isOfflineError({ name: "MongoServerSelectionError" })).toBe(true);
expect(isOfflineError({ name: "MongoNetworkError" })).toBe(true);
expect(isOfflineError({ name: "MongoNetworkTimeoutError" })).toBe(true);
expect(isOfflineError({ name: "MongoTopologyClosedError" })).toBe(true);
});

test("identifies message text containing offline indicators", () => {
expect(
isOfflineError(
new Error(
"Failed to fetch MySQL database stats: getaddrinfo ENOTFOUND lms-yashh56.d.aivencloud.com",
),
),
).toBe(true);
expect(isOfflineError(new Error("connect ECONNREFUSED 127.0.0.1:3306"))).toBe(true);
expect(
isOfflineError(
new Error("Failed to fetch MySQL database stats: connect ECONNREFUSED 127.0.0.1:3306"),
),
).toBe(true);
expect(isOfflineError(new Error("Server selection timed out after 30000 ms"))).toBe(true);
expect(isOfflineError(new Error("Topology is closed"))).toBe(true);
expect(isOfflineError(new Error("Connection terminated unexpectedly"))).toBe(true);
expect(isOfflineError("Database is offline")).toBe(true);
});

test("identifies cause error as offline when cause matches", () => {
const errorWithCause = new Error("Wrapper");
(errorWithCause as any).cause = { code: "ECONNREFUSED" };
expect(isOfflineError(errorWithCause)).toBe(true);
});

test("returns false for non-offline errors", () => {
expect(isOfflineError(null)).toBe(false);
expect(isOfflineError(undefined)).toBe(false);
expect(isOfflineError(new Error("Table 'users' does not exist"))).toBe(false);
expect(isOfflineError(new Error("Table 'offline_orders' does not exist"))).toBe(false);
expect(
isOfflineError(
new Error(
"Failed to fetch MySQL database stats: Access denied for user 'root'@'localhost'",
),
),
).toBe(false);
expect(isOfflineError(new Error("Syntax error in SQL statement"))).toBe(false);
expect(
isOfflineError({ code: "ER_PARSE_ERROR", message: "You have an error in your SQL" }),
).toBe(false);
});
});

describe("Handlers graceful offline error handling", () => {
const createMockRpc = () => ({
sendResponse: jest.fn(),
sendError: jest.fn(),
});

const createMockLogger = () => ({
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
});

test("DatabaseHandlers.handleListTables returns empty data with isOffline: true when offline", async () => {
const mockRpc = createMockRpc();
const mockLogger = createMockLogger();
const mockDbService = {
withConnection: jest
.fn<any>()
.mockRejectedValue(new Error("getaddrinfo ENOTFOUND remote-cluster.example.com")),
};
const mockQueryExecutor = {};

const handlers = new DatabaseHandlers(
mockRpc as any,
mockLogger as any,
mockDbService as any,
mockQueryExecutor as any,
);

await handlers.handleListTables({ id: "offline-db-1" }, 101);

expect(mockRpc.sendResponse).toHaveBeenCalledWith(101, {
ok: true,
data: [],
isOffline: true,
});
expect(mockRpc.sendError).not.toHaveBeenCalled();
expect(mockLogger.error).not.toHaveBeenCalled();
expect(mockLogger.warn).toHaveBeenCalled();
});

test("DatabaseHandlers.handleListSchemas returns empty data with isOffline: true when offline", async () => {
const mockRpc = createMockRpc();
const mockLogger = createMockLogger();
const mockDbService = {
withConnection: jest
.fn<any>()
.mockRejectedValue(new Error("connect ECONNREFUSED 127.0.0.1:5432")),
};
const mockQueryExecutor = {};

const handlers = new DatabaseHandlers(
mockRpc as any,
mockLogger as any,
mockDbService as any,
mockQueryExecutor as any,
);

await handlers.handleListSchemas({ id: "offline-db-2" }, 102);

expect(mockRpc.sendResponse).toHaveBeenCalledWith(102, {
ok: true,
data: [],
isOffline: true,
});
expect(mockRpc.sendError).not.toHaveBeenCalled();
expect(mockLogger.error).not.toHaveBeenCalled();
});

test("DatabaseHandlers.handleTestConnection returns disconnected with isOffline: true when offline", async () => {
const mockRpc = createMockRpc();
const mockLogger = createMockLogger();
const mockDbService = {
withConnection: jest
.fn<any>()
.mockRejectedValue(new Error("connect ETIMEDOUT 192.168.1.100:3306")),
};
const mockQueryExecutor = {};

const handlers = new DatabaseHandlers(
mockRpc as any,
mockLogger as any,
mockDbService as any,
mockQueryExecutor as any,
);

await handlers.handleTestConnection({ id: "offline-db-3" }, 103);

expect(mockRpc.sendResponse).toHaveBeenCalledWith(
103,
expect.objectContaining({
ok: true,
data: expect.objectContaining({
ok: false,
status: "disconnected",
isOffline: true,
}),
}),
);
expect(mockLogger.error).not.toHaveBeenCalled();
expect(mockLogger.warn).toHaveBeenCalled();
});

test("StatsHandlers.handleGetStats returns zeroed stats with isOffline: true when offline", async () => {
const mockRpc = createMockRpc();
const mockLogger = createMockLogger();
const mockDbService = {
getDatabaseConnection: jest
.fn<any>()
.mockRejectedValue(new Error("getaddrinfo ENOTFOUND my-cluster.mongodb.net")),
};
const mockQueryExecutor = {};

const handlers = new StatsHandlers(
mockRpc as any,
mockLogger as any,
mockDbService as any,
mockQueryExecutor as any,
);

await handlers.handleGetStats({ id: "offline-mongo-1" }, 104);

expect(mockRpc.sendResponse).toHaveBeenCalledWith(104, {
ok: true,
data: { tables: 0, rows: 0, sizeBytes: 0 },
isOffline: true,
});
expect(mockRpc.sendError).not.toHaveBeenCalled();
expect(mockLogger.error).not.toHaveBeenCalled();
expect(mockLogger.warn).toHaveBeenCalled();
});
});
Loading
Loading