{"record":{"id":"a5e73bf5491d6f75","repo":"Mintplex-Labs/anything-llm","slug":"error-setting-suggested-messages","errorCode":null,"errorMessage":"Error setting suggested messages.","messagePattern":"Error setting suggested messages\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/models/workspace.js","lineNumber":333,"sourceCode":"      .then((res) => {\n        if (!res.ok) throw new Error(\"Could not fetch suggested messages.\");\n        return res.json();\n      })\n      .then((res) => res.suggestedMessages)\n      .catch((e) => {\n        console.error(e);\n        return null;\n      });\n  },\n  setSuggestedMessages: async function (slug, messages) {\n    return fetch(`${API_BASE}/workspace/${slug}/suggested-messages`, {\n      method: \"POST\",\n      headers: baseHeaders(),\n      body: JSON.stringify({ messages }),\n    })\n      .then((res) => {\n        if (!res.ok) {\n          throw new Error(\n            res.statusText || \"Error setting suggested messages.\"\n          );\n        }\n        return { success: true, ...res.json() };\n      })\n      .catch((e) => {\n        console.error(e);\n        return { success: false, error: e.message };\n      });\n  },\n  setPinForDocument: async function (slug, docPath, pinStatus) {\n    return fetch(`${API_BASE}/workspace/${slug}/update-pin`, {\n      method: \"POST\",\n      headers: baseHeaders(),\n      body: JSON.stringify({ docPath, pinStatus }),\n    })\n      .then((res) => {\n        if (!res.ok) {","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/frontend/src/models/workspace.js#L315-L351","documentation":"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 }.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nreturn { success: true, ...res.json() };  // spreads a Promise!\n\n// after\nconst data = await res.json();\nreturn { success: true, ...data };","handlingStrategy":"validation","validationCode":"// Validate messages shape and slug before posting.\nfunction isValidSuggestedMessages(slug, messages) {\n  return typeof slug === 'string' && slug.trim().length > 0\n    && Array.isArray(messages)\n    && messages.every(m => typeof m === 'string' && m.trim().length > 0);\n}","typeGuard":"function isSetMessagesResult(x): x is { success: true } {\n  return x && x.success === true;\n}","tryCatchPattern":"const { success, error } = await Workspace.setSuggestedMessages(slug, messages);\nif (!success) showToast(error || 'Could not save suggested messages.');","preventionTips":["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."],"tags":["frontend","api-client","workspace","validation","bug","network"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}