Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Humanize raw backend errors on the connections list

rcourtman8504d97c5b9a
diff --git a/frontend-modern/src/components/Settings/useConnectionsLedger.ts b/frontend-modern/src/components/Settings/useConnectionsLedger.ts
index 7b36797b1f..47dc75df7b 100644
--- a/frontend-modern/src/components/Settings/useConnectionsLedger.ts
+++ b/frontend-modern/src/components/Settings/useConnectionsLedger.ts
@@ -1,4 +1,5 @@
import { createEffect, createMemo, createResource, onCleanup } from 'solid-js';
+import { formatConnectionErrorMessage } from '@/utils/connectionErrorPresentation';
import {
ConnectionsAPI,
type Connection,
@@ -241,9 +242,13 @@ const buildRow = (
const attachedConnections = componentConnections.filter(
(connection) => connection.id !== primaryConnection.id,
);
- const lastErrorMessage =
+ // Run raw backend error chains through the user-facing presenter so the
+ // connection table doesn't surface implementation strings like 'context
+ // deadline exceeded' or 'Client.Timeout exceeded while awaiting headers'.
+ const rawLastErrorMessage =
primaryConnection.lastError?.message ??
attachedConnections.find((connection) => connection.lastError?.message)?.lastError?.message;
+ const lastErrorMessage = formatConnectionErrorMessage(rawLastErrorMessage) ?? undefined;
const hostTelemetryLabel = surfaceLabel('host');
const coverageLabels = isCluster
? coverageLabelsFor(componentConnections).filter((label) => label !== hostTelemetryLabel)
diff --git a/frontend-modern/src/utils/__tests__/connectionErrorPresentation.test.ts b/frontend-modern/src/utils/__tests__/connectionErrorPresentation.test.ts
new file mode 100644
index 0000000000..00e1b0ed6d
--- /dev/null
+++ b/frontend-modern/src/utils/__tests__/connectionErrorPresentation.test.ts
@@ -0,0 +1,82 @@
+import { describe, expect, it } from 'vitest';
+
+import {
+ formatConnectionErrorMessage,
+ humanizeConnectionError,
+} from '../connectionErrorPresentation';
+
+describe('humanizeConnectionError', () => {
+ it('returns null for empty input', () => {
+ expect(humanizeConnectionError(undefined)).toBeNull();
+ expect(humanizeConnectionError(null)).toBeNull();
+ expect(humanizeConnectionError('')).toBeNull();
+ expect(humanizeConnectionError(' ')).toBeNull();
+ });
+
+ it('humanizes Go context-deadline timeouts on poll-style errors', () => {
+ const raw =
+ 'poll_nodes failed on delly: Get "https://192.168.0.134:8006/api2/json/nodes": context deadline exceeded (Client.Timeout exceeded while awaiting headers)';
+ const result = humanizeConnectionError(raw);
+ expect(result?.headline).toBe('Connection timed out');
+ expect(result?.hint).toMatch(/host is reachable/i);
+ });
+
+ it('classifies DNS lookup failures as host not found', () => {
+ const result = humanizeConnectionError(
+ 'Get "https://truenas.lan/api/v2.0/system/info": dial tcp: lookup truenas.lan: no such host',
+ );
+ expect(result?.headline).toBe('Host not found');
+ expect(result?.hint).toMatch(/hostname or IP/i);
+ });
+
+ it('classifies connection refused', () => {
+ const result = humanizeConnectionError(
+ 'Get "https://192.0.2.7:8006/": dial tcp 192.0.2.7:8006: connect: connection refused',
+ );
+ expect(result?.headline).toBe('Connection refused');
+ });
+
+ it('classifies untrusted certs as TLS not trusted with a remediation hint', () => {
+ const result = humanizeConnectionError(
+ 'Get "https://truenas.lan/": x509: certificate signed by unknown authority',
+ );
+ expect(result?.headline).toBe('TLS certificate not trusted');
+ expect(result?.hint).toMatch(/fingerprint|TLS verification/i);
+ });
+
+ it('classifies HTTP 401 as authentication failed', () => {
+ const result = humanizeConnectionError(
+ 'Get "https://pve/api2/json/version": 401 Unauthorized',
+ );
+ expect(result?.headline).toBe('Authentication failed');
+ });
+
+ it('classifies HTTP 403 as permission denied', () => {
+ const result = humanizeConnectionError(
+ 'Get "https://pve/api2/json/cluster/status": 403 Forbidden',
+ );
+ expect(result?.headline).toBe('Permission denied');
+ });
+
+ it('falls back to a cleaned message for unknown errors', () => {
+ const result = humanizeConnectionError(
+ 'poll_nodes failed on delly: Get "https://example.com/foo": something genuinely novel',
+ );
+ expect(result?.headline).toBe('something genuinely novel');
+ expect(result?.hint).toBeNull();
+ });
+
+ it('formats a single-line message with hint for known patterns', () => {
+ const formatted = formatConnectionErrorMessage(
+ 'poll_nodes failed on pi: Get "https://pi:8006/api2/json/nodes": context deadline exceeded',
+ );
+ expect(formatted).toBe(
+ 'Connection timed out. Check the host is reachable, the port is correct, and the network path is open.',
+ );
+ });
+
+ it('formats unknown errors as headline only', () => {
+ const formatted = formatConnectionErrorMessage('a totally unknown failure mode');
+ expect(formatted).toBe('a totally unknown failure mode');
+ });
+});
diff --git a/frontend-modern/src/utils/connectionErrorPresentation.ts b/frontend-modern/src/utils/connectionErrorPresentation.ts
new file mode 100644
index 0000000000..a521e4d38c
--- /dev/null
+++ b/frontend-modern/src/utils/connectionErrorPresentation.ts
@@ -0,0 +1,123 @@
+/**
+ * connectionErrorPresentation
+ *
+ * Translates raw backend connection errors (often Go error chains exposing
+ * implementation detail like 'context deadline exceeded' or
+ * 'Client.Timeout exceeded while awaiting headers') into short user-facing
+ * messages.
+ *
+ * The connection-table row already shows the connection name and host, so
+ * the humanized message focuses on the failure mode and a short remediation
+ * hint without restating identity.
+ *
+ * For unknown errors we fall back to the raw message stripped of the most
+ * common implementation prefixes so it's at least readable.
+ */
+
+const POLL_PREFIX_PATTERN = /^poll_[a-z_]+\s+failed\s+on\s+[^:]+:\s*/i;
+// Patterns from common Go error chains: `Get "https://...":`, `Post "..."`.
+const HTTP_VERB_PATTERN = /\b(?:Get|Post|Put|Delete|Patch|Head)\s+"[^"]+":\s*/g;
+
+interface HumanizedConnectionError {
+ /** Short headline ('Connection timed out', 'Host not found', etc.). */
+ headline: string;
+ /** One-line remediation hint, or null when none applies. */
+ hint: string | null;
+}
+
+const TIMEOUT_HINT =
+ 'Check the host is reachable, the port is correct, and the network path is open.';
+const TLS_HINT =
+ 'Verify the certificate or pin a fingerprint in TLS settings, or disable TLS verification temporarily for testing.';
+const AUTH_HINT = 'Re-check the API token or username/password.';
+
+const HUMANIZED_PATTERNS: { match: RegExp; headline: string; hint: string | null }[] = [
+ {
+ match: /context deadline exceeded|Client\.Timeout|i\/o timeout|deadline exceeded/i,
+ headline: 'Connection timed out',
+ hint: TIMEOUT_HINT,
+ },
+ {
+ match: /no such host|dns:.*lookup|name does not resolve/i,
+ headline: 'Host not found',
+ hint: 'Check the hostname or IP address.',
+ },
+ {
+ match: /connection refused|connect:\s*connection refused/i,
+ headline: 'Connection refused',
+ hint: 'The host is reachable but rejected the connection on this port. Check the port is correct and the service is running.',
+ },
+ {
+ match: /no route to host|network is unreachable/i,
+ headline: 'No network route to host',
+ hint: 'The host cannot be reached from this Pulse instance. Check VPN, firewall, or VLAN configuration.',
+ },
+ {
+ match: /x509:.*signed by unknown authority|certificate signed by unknown/i,
+ headline: 'TLS certificate not trusted',
+ hint: TLS_HINT,
+ },
+ {
+ match: /x509:.*expired|certificate has expired/i,
+ headline: 'TLS certificate expired',
+ hint: TLS_HINT,
+ },
+ {
+ match: /tls:\s*handshake failure|tls handshake|bad certificate/i,
+ headline: 'TLS handshake failed',
+ hint: TLS_HINT,
+ },
+ {
+ match: /\b401\b|unauthorized|invalid (?:credentials|api token)/i,
+ headline: 'Authentication failed',
+ hint: AUTH_HINT,
+ },
+ {
+ match: /\b403\b|forbidden|permission denied/i,
+ headline: 'Permission denied',
+ hint: 'The credentials connected, but the user/token lacks the required role.',
+ },
+ {
+ match: /\b404\b|not found/i,
+ headline: 'Endpoint not found',
+ hint: 'Pulse reached the host but the API path is missing. Check the URL path or the platform version.',
+ },
+ {
+ match: /\b5\d{2}\b|server error|internal error/i,
+ headline: 'Server error',
+ hint: 'The platform returned a server error. Check the platform logs for the underlying cause.',
+ },
+];
+
+const stripImplementationPrefixes = (raw: string): string =>
+ raw
+ .replace(POLL_PREFIX_PATTERN, '')
+ .replace(HTTP_VERB_PATTERN, '')
+ .trim();
+
+export const humanizeConnectionError = (raw?: string | null): HumanizedConnectionError | null => {
+ if (!raw) return null;
+ const trimmed = raw.trim();
+ if (!trimmed) return null;
+
+ for (const pattern of HUMANIZED_PATTERNS) {
+ if (pattern.match.test(trimmed)) {
+ return { headline: pattern.headline, hint: pattern.hint };
+ }
+ }
+
+ // Unknown error: fall back to the raw text with the most common
+ // implementation-leaking prefixes peeled off so it's at least readable.
+ const cleaned = stripImplementationPrefixes(trimmed);
+ return { headline: cleaned || 'Connection error', hint: null };
+};
+
+/**
+ * Render a single-line message suitable for inline display in a table row.
+ * Combines headline and hint when both apply.
+ */
+export const formatConnectionErrorMessage = (raw?: string | null): string | null => {
+ const humanized = humanizeConnectionError(raw);
+ if (!humanized) return null;
+ return humanized.hint ? `${humanized.headline}. ${humanized.hint}` : humanized.headline;
+};