Mintplex-Labs/anything-llm · error · Error
Error setting suggested messages.
Error message
Error setting suggested messages.
What it means
Thrown by Workspace.setSuggestedMessages when POST /workspace/:slug/suggested-messages returns non-2xx. The fallback message is used only when res.statusText is empty. There is a latent bug in the success branch: `return { success: true, ...res.json() }` spreads a Promise (res.json() is not awaited), so even on success the merge is broken — but the error in scope is the non-ok throw. The .catch returns { success: false, error }.
Source
Thrown at frontend/src/models/workspace.js:333
.then((res) => {
if (!res.ok) throw new Error("Could not fetch suggested messages.");
return res.json();
})
.then((res) => res.suggestedMessages)
.catch((e) => {
console.error(e);
return null;
});
},
setSuggestedMessages: async function (slug, messages) {
return fetch(`${API_BASE}/workspace/${slug}/suggested-messages`, {
method: "POST",
headers: baseHeaders(),
body: JSON.stringify({ messages }),
})
.then((res) => {
if (!res.ok) {
throw new Error(
res.statusText || "Error setting suggested messages."
);
}
return { success: true, ...res.json() };
})
.catch((e) => {
console.error(e);
return { success: false, error: e.message };
});
},
setPinForDocument: async function (slug, docPath, pinStatus) {
return fetch(`${API_BASE}/workspace/${slug}/update-pin`, {
method: "POST",
headers: baseHeaders(),
body: JSON.stringify({ docPath, pinStatus }),
})
.then((res) => {
if (!res.ok) {View on GitHub (pinned to 526360e320)
Solutions
- Confirm the slug is current by refetching the workspace before saving.
- Validate messages is a non-empty array of trimmed non-empty strings before posting.
- Await res.json() in the success branch — the current code spreads a Promise, which is a separate defect.
- Surface res.status in the error message for diagnosis.
Example fix
// before
return { success: true, ...res.json() }; // spreads a Promise!
// after
const data = await res.json();
return { success: true, ...data }; Defensive patterns
Strategy: validation
Validate before calling
// Validate messages shape and slug before posting.
function isValidSuggestedMessages(slug, messages) {
return typeof slug === 'string' && slug.trim().length > 0
&& Array.isArray(messages)
&& messages.every(m => typeof m === 'string' && m.trim().length > 0);
} Type guard
function isSetMessagesResult(x): x is { success: true } {
return x && x.success === true;
} Try / catch
const { success, error } = await Workspace.setSuggestedMessages(slug, messages);
if (!success) showToast(error || 'Could not save suggested messages.'); Prevention
- Trim and validate each message string before posting.
- Refetch the workspace to confirm the slug is current.
- Fix the latent bug: await res.json() instead of spreading the Promise in the success branch.
When it happens
Trigger: The workspace slug does not exist (404), the messages array fails server-side validation (wrong shape, too many entries, content too long), or the user lacks write permission on the workspace.
Common situations: Slug from stale props after the workspace was renamed/deleted; messages containing only empty strings after a trim; permission mismatch when a read-only viewer opens settings; the success-path Promise-spread bug masking the real response.
Related errors
- ${res.statusText || "Error generating api key."}
- ${res.error || "Failed to save flow"}
- ${res.error || "Failed to get flow"}
- ${res.error || "Failed to delete flow"}
- ${res.error || "Failed to toggle flow"}
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/a5e73bf5491d6f75.
Report an issue: GitHub.