Skip to content

Commit 83bfba8

Browse files
raymyersAlexCuadron
authored andcommittedJan 13, 2025
Provide a clearer error message when settings are missing midsession (All-Hands-AI#6158)
1 parent 3eb2aea commit 83bfba8

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed
 

‎frontend/__tests__/context/ws-client-provider.test.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,17 @@ describe("Propagate error message", () => {
2727
type: 'error'
2828
});
2929
});
30+
31+
it("should display error including translation id when present", () => {
32+
const message = "We have a problem!"
33+
const addErrorMessageSpy = vi.spyOn(ChatSlice, "addErrorMessage")
34+
updateStatusWhenErrorMessagePresent({message, data: {msg_id: '..id..'}})
35+
36+
expect(addErrorMessageSpy).toHaveBeenCalledWith({
37+
message,
38+
id: '..id..',
39+
status_update: true,
40+
type: 'error'
41+
});
42+
});
3043
});

‎frontend/src/context/ws-client-provider.tsx

+24-7
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,33 @@ interface WsClientProviderProps {
6767
conversationId: string;
6868
}
6969

70-
export function updateStatusWhenErrorMessagePresent(data: unknown) {
71-
if (
72-
data &&
73-
typeof data === "object" &&
74-
"message" in data &&
75-
typeof data.message === "string"
76-
) {
70+
interface ErrorArg {
71+
message?: string;
72+
data?: ErrorArgData | unknown;
73+
}
74+
75+
interface ErrorArgData {
76+
msg_id: string;
77+
}
78+
79+
export function updateStatusWhenErrorMessagePresent(data: ErrorArg | unknown) {
80+
const isObject = (val: unknown): val is object =>
81+
!!val && typeof val === "object";
82+
const isString = (val: unknown): val is string => typeof val === "string";
83+
if (isObject(data) && "message" in data && isString(data.message)) {
84+
let msgId: string | undefined;
85+
if (
86+
"data" in data &&
87+
isObject(data.data) &&
88+
"msg_id" in data.data &&
89+
isString(data.data.msg_id)
90+
) {
91+
msgId = data.data.msg_id;
92+
}
7793
handleStatusMessage({
7894
type: "error",
7995
message: data.message,
96+
id: msgId,
8097
status_update: true,
8198
});
8299
}

‎frontend/src/i18n/translation.json

+4
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@
454454
"fr": "Nous avons modifié certains paramètres dans la dernière mise à jour. Prenez un moment pour les examiner.",
455455
"tr": "Son güncellemede bazı ayarları değiştirdik. Gözden geçirmek için bir dakikanızı ayırın."
456456
},
457+
"CONFIGURATION$SETTINGS_NOT_FOUND": {
458+
"en": "Settings not found. Please check your API key",
459+
"es": "Configuraciones no encontradas. Por favor revisa tu API key"
460+
},
457461
"CONFIGURATION$AGENT_LOADING": {
458462
"en": "Please wait while the agent loads. This may take a few minutes...",
459463
"de": "Bitte warten Sie, während der Agent lädt. Das kann ein paar Minuten dauern...",

‎openhands/server/listen_socket.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ async def connect(connection_id: str, environ, auth):
5757
settings = await settings_store.load()
5858

5959
if not settings:
60-
raise ConnectionRefusedError('Settings not found')
60+
raise ConnectionRefusedError(
61+
'Settings not found', {'msg_id': 'CONFIGURATION$SETTINGS_NOT_FOUND'}
62+
)
6163

6264
try:
6365
event_stream = await session_manager.join_conversation(

0 commit comments

Comments
 (0)