Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

improve error handling

x473aa579b0fb
diff --git a/frontend/src/pages/pam/PamAccountAccessPage/useRdpSession.ts b/frontend/src/pages/pam/PamAccountAccessPage/useRdpSession.ts
index aadf1fc96b..099c554144 100644
--- a/frontend/src/pages/pam/PamAccountAccessPage/useRdpSession.ts
+++ b/frontend/src/pages/pam/PamAccountAccessPage/useRdpSession.ts
@@ -17,6 +17,40 @@ const DEFAULT_DESKTOP_SIZE = { width: 1920, height: 1080 };
const STATUS_BAR_HEIGHT = 33;
+// Mirrors the IronErrorKind enum, indexed by its discriminant
+const IRON_ERROR_KIND_NAMES = [
+ "General",
+ "WrongPassword",
+ "LogonFailure",
+ "AccessDenied",
+ "RDCleanPath",
+ "ProxyConnect",
+ "NegotiationFailure"
+];
+
+const callSafely = (fn: unknown): string | null => {
+ if (typeof fn !== "function") return null;
+ try {
+ const result = (fn as () => unknown)();
+ return typeof result === "string" && result.trim() ? result.trim() : null;
+ } catch {
+ return null;
+ }
+};
+
+const stringifyRdpError = (kind: unknown, err: unknown): string => {
+ const kindName = typeof kind === "number" ? IRON_ERROR_KIND_NAMES[kind] : undefined;
+ const backtrace = callSafely((err as { backtrace?: unknown })?.backtrace);
+
+ if (kindName && backtrace) return `${kindName}: ${backtrace}`;
+ if (kindName) return kindName;
+ if (backtrace) return backtrace;
+ if (typeof kind === "string" && kind.trim()) return kind;
+ if (err instanceof Error && err.message) return err.message;
+ if (typeof err === "string" && err.trim()) return err;
+ return "Connection failed";
+};
+
// WASM reads window.innerHeight for fit scaling, not the container
const innerHeightDescriptor =
Object.getOwnPropertyDescriptor(window, "innerHeight") ??
@@ -184,7 +218,7 @@ export const useRdpSession = ({
// eslint-disable-next-line no-console
console.error("RDP session failed:", kind, ironErr.backtrace?.() ?? err);
if (!isCurrent()) return;
- const detail = typeof kind === "string" ? kind : String(err);
+ const detail = stringifyRdpError(kind, err);
setError(detail);
createNotification({
type: "error",