feat(desktop): unify frontend error notices
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
89
apps/desktop/src/lib/operator-notices.test.ts
Normal file
89
apps/desktop/src/lib/operator-notices.test.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
createAccentNotice,
|
||||
createNeutralNotice,
|
||||
toBackendError,
|
||||
toBackendErrorNotice,
|
||||
} from "./operator-notices";
|
||||
|
||||
describe("operator notices", () => {
|
||||
it("creates explicit accent notices for successful actions", () => {
|
||||
expect(createAccentNotice("Saved")).toEqual({
|
||||
tone: "accent",
|
||||
message: "Saved",
|
||||
});
|
||||
});
|
||||
|
||||
it("normalizes unknown thrown values into internal backend errors", () => {
|
||||
expect(toBackendError(new Error("boom"))).toEqual({
|
||||
code: "internal",
|
||||
message: "boom",
|
||||
detail: null,
|
||||
});
|
||||
});
|
||||
|
||||
it("maps authentication failures to a consistent operator-facing notice", () => {
|
||||
expect(
|
||||
toBackendErrorNotice(
|
||||
{
|
||||
code: "authentication_failed",
|
||||
message: "Authentication failed.",
|
||||
detail: "WRONGPASS invalid username-password pair",
|
||||
},
|
||||
{
|
||||
operation: "connection_test",
|
||||
connectionName: "redis-local-fixture",
|
||||
databaseLabel: "db0",
|
||||
},
|
||||
),
|
||||
).toEqual({
|
||||
tone: "danger",
|
||||
message:
|
||||
"Redis rejected the credentials used while testing redis-local-fixture on db0. Verify username, password, and ACL scope for the selected connection. Backend detail: Authentication failed. (WRONGPASS invalid username-password pair).",
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps unsupported operations in a non-destructive neutral notice", () => {
|
||||
expect(
|
||||
toBackendErrorNotice(
|
||||
{
|
||||
code: "unsupported_operation",
|
||||
message: "Only string replacement is supported in V1.",
|
||||
detail: null,
|
||||
},
|
||||
{
|
||||
operation: "value_write",
|
||||
connectionName: "redis-local-fixture",
|
||||
databaseLabel: "db0",
|
||||
keyName: "session:42",
|
||||
},
|
||||
),
|
||||
).toEqual(
|
||||
createNeutralNotice(
|
||||
"The current desktop contract does not allow saving session:42 on redis-local-fixture / db0 yet. Stay on the visible read-only path or wait for a backend contract change before retrying. Backend detail: Only string replacement is supported in V1.",
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it("describes command failures with command and scope context", () => {
|
||||
expect(
|
||||
toBackendErrorNotice(
|
||||
{
|
||||
code: "command_failed",
|
||||
message: "ERR unknown command 'FOOO'",
|
||||
detail: null,
|
||||
},
|
||||
{
|
||||
operation: "command_execution",
|
||||
connectionName: "redis-local-fixture",
|
||||
databaseLabel: "db0",
|
||||
commandName: "fooo",
|
||||
},
|
||||
),
|
||||
).toEqual({
|
||||
tone: "danger",
|
||||
message:
|
||||
"Redis returned an error while running FOOO on redis-local-fixture / db0. Adjust the Redis input first; retrying the same command unchanged is unlikely to help. Backend detail: ERR unknown command 'FOOO'.",
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user