Skip to content

Commit 65499d1

Browse files
committed
Cleanup error messages; ReturnTypes aren't needed
1 parent 326b730 commit 65499d1

File tree

6 files changed

+55
-33
lines changed

6 files changed

+55
-33
lines changed

js/chat/chat.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { LitElement, html } from "lit";
22
import { unsafeHTML } from "lit-html/directives/unsafe-html.js";
33
import { property } from "lit/decorators.js";
44

5-
import { LightElement, createElement } from "../utils/_utils";
5+
import {
6+
LightElement,
7+
createElement,
8+
showShinyClientMessage,
9+
} from "../utils/_utils";
610

711
type ContentType = "markdown" | "html" | "text";
812

@@ -55,7 +59,7 @@ class ChatMessage extends LightElement {
5559
@property() content_type: ContentType = "markdown";
5660
@property({ type: Boolean, reflect: true }) streaming = false;
5761

58-
render(): ReturnType<LitElement["render"]> {
62+
render() {
5963
const noContent = this.content.trim().length === 0;
6064
const icon = noContent ? ICONS.dots_fade : ICONS.robot;
6165

@@ -73,7 +77,7 @@ class ChatMessage extends LightElement {
7377
class ChatUserMessage extends LightElement {
7478
@property() content = "...";
7579

76-
render(): ReturnType<LitElement["render"]> {
80+
render() {
7781
return html`
7882
<shiny-markdown-stream
7983
content=${this.content}
@@ -84,7 +88,7 @@ class ChatUserMessage extends LightElement {
8488
}
8589

8690
class ChatMessages extends LightElement {
87-
render(): ReturnType<LitElement["render"]> {
91+
render() {
8892
return html``;
8993
}
9094
}
@@ -109,7 +113,7 @@ class ChatInput extends LightElement {
109113
return this.querySelector("button") as HTMLButtonElement;
110114
}
111115

112-
render(): ReturnType<LitElement["render"]> {
116+
render() {
113117
const icon =
114118
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-arrow-up-circle-fill" viewBox="0 0 16 16"><path d="M16 8A8 8 0 1 0 0 8a8 8 0 0 0 16 0m-7.5 3.5a.5.5 0 0 1-1 0V5.707L5.354 7.854a.5.5 0 1 1-.708-.708l3-3a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 5.707z"/></svg>';
115119

@@ -199,7 +203,7 @@ class ChatContainer extends LightElement {
199203
return last ? (last as ChatMessage) : null;
200204
}
201205

202-
render(): ReturnType<LitElement["render"]> {
206+
render() {
203207
return html``;
204208
}
205209

@@ -352,9 +356,21 @@ $(function () {
352356
const evt = new CustomEvent(message.handler, {
353357
detail: message.obj,
354358
});
359+
355360
const el = document.getElementById(message.id);
356-
// TODO: throw an error if the element is not found?
357-
el?.dispatchEvent(evt);
361+
362+
if (!el) {
363+
const errMsg = `
364+
Unable to handle Chat() message since element with id ${message.id} wasn't
365+
found. Do you need to call .ui() (Express) or need a
366+
chat_ui('${message.id}') in the UI (Core)?
367+
`;
368+
console.error(errMsg);
369+
showShinyClientMessage({ message: errMsg, status: "error" });
370+
return;
371+
}
372+
373+
el.dispatchEvent(evt);
358374
}
359375
);
360376
});

js/markdown-stream/markdown-stream.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ function handleMessage(message: ContentMessage | IsStreamingMessage): void {
214214

215215
if (!el) {
216216
const errMsg = `
217-
Cannot handle MarkdownStream message: element with id ${message.id} not found.
218-
Do you need to call .ui() (Express) or fix the id (Core)?
217+
Unable to handle MarkdownStream() message since element with id ${message.id}
218+
wasn't found. Do you need to call .ui() (Express) or need a
219+
output_markdown_stream('${message.id}') in the UI (Core)?
219220
`;
220221
console.error(errMsg);
221222
showShinyClientMessage({ message: errMsg, status: "error" });

0 commit comments

Comments
 (0)