{"record":{"id":"678e91b55a1e8885","repo":"Mintplex-Labs/anything-llm","slug":"message-is-empty-678e91","errorCode":null,"errorMessage":"Message is empty.","messagePattern":"Message is empty\\.","errorType":"http","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"server/utils/middleware/embedMiddleware.js","lineNumber":112,"sourceCode":"      });\n      return;\n    }\n\n    const { sessionId, message } = reqBody(request);\n    if (typeof sessionId !== \"string\" || !validate(String(sessionId))) {\n      response.status(404).json({\n        id: uuidv4(),\n        type: \"abort\",\n        textResponse: null,\n        sources: [],\n        close: true,\n        error: \"Invalid session ID.\",\n      });\n      return;\n    }\n\n    if (!message?.length || !VALID_CHAT_MODE.includes(embed.chat_mode)) {\n      response.status(400).json({\n        id: uuidv4(),\n        type: \"abort\",\n        textResponse: null,\n        sources: [],\n        close: true,\n        error: !message?.length\n          ? \"Message is empty.\"\n          : `${embed.chat_mode} is not a valid mode.`,\n      });\n      return;\n    }\n\n    if (\n      !isNaN(embed.max_chats_per_day) &&\n      Number(embed.max_chats_per_day) > 0\n    ) {\n      const dailyChatCount = await EmbedChats.count({\n        embed_id: embed.id,","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/middleware/embedMiddleware.js#L94-L130","documentation":"Message validation inside canRespond: the same 400 response covers two conditions, and when !message?.length the payload reports 'Message is empty.'. Anything falsy or zero-length — empty string, null, undefined — triggers it. The embed itself and session are fine; only the text is missing.","triggerScenarios":"Widget sends {sessionId: '<uuid>'} without a message key; whitespace-only string is NOT caught by length check but a truly empty string is; double-submit where the input was cleared before the request body was built.","commonSituations":"Enter keypress handler firing on an empty textarea; message state cleared optimistically before serialization; test scripts sending only sessionId.","solutions":["Disable the send action when the trimmed input is empty","Build the request body from the captured text before clearing the input state","Send {\"message\": \"...\", \"sessionId\": \"<uuid>\"} as JSON with Content-Type: application/json"],"exampleFix":"// before\nif (e.key === 'Enter') send({ sessionId }); // message omitted -> 400\n\n// after\nconst text = input.value.trim();\nif (!text) return; // guard\nsend({ sessionId, message: text });","handlingStrategy":"validation","validationCode":"const text = input.value.trim();\nif (text.length === 0) return; // never send an empty message\nsend({ sessionId, message: text });","typeGuard":"const isNonEmptyMessage = (m) => typeof m === 'string' && m.length > 0;","tryCatchPattern":"if (res.status === 400) {\n  const data = await res.json();\n  if (data.error === 'Message is empty.') reEnableSendButton(); // client bug, fix guard\n}","preventionTips":["Disable send/Enter handlers on empty trimmed input","Capture the message text before clearing input state","Assert payload shape in one shared send() helper"],"tags":["embed","validation","http-400","empty-message"],"backgroundTag":"missing-required-field","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}