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
12 changes: 8 additions & 4 deletions src/lib/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,15 @@ User: ${userMessage}`;
);
});
} catch (err) {
// Synchronous setup failures (most importantly `!this.isReady` — the Puter
// bridge hasn't finished its handshake) must PROPAGATE, not resolve to a
// string. The sole caller (sidebar-chat) discards chatStream's return value
// and relies on a thrown error to render the error bubble + retry button;
// returning a string here left the "thinking…" spinner stranded forever
// with no error and no retry. (Promise-path failures — timeout, abort,
// success:false — already reject and are unaffected.)
console.error('[SkillBridge] Chat stream error:', err);
return (
(typeof CHAT_ERROR_LABELS !== 'undefined' && CHAT_ERROR_LABELS[targetLang]) ||
'Sorry, I could not generate a response. Please try again.'
);
throw err;
}
}

Expand Down
12 changes: 12 additions & 0 deletions tests/translator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,15 @@ describe('Language JSON files', () => {
});
});
});

describe('chatStream — bridge-not-ready propagates as a rejection', () => {
test('rejects (does not silently resolve to a string) when the bridge is not ready', async () => {
const t = new SkilljarTranslator();
t.isReady = false;
// The sole caller (sidebar-chat) discards chatStream's return value and
// relies on a thrown error to render the error bubble + retry button. If
// this resolves to a string instead, the "thinking…" spinner is stranded
// forever with no error and no retry.
await expect(t.chatStream('hello', 'ko', '', () => {}, {})).rejects.toThrow('Bridge not ready');
});
});
Loading