{"record":{"id":"e30a468bcd7d7798","repo":"Mintplex-Labs/anything-llm","slug":"daily-message-limit-must-be-null-or-a-number-great","errorCode":null,"errorMessage":"Daily message limit must be null or a number greater than or equal to 1","messagePattern":"Daily message limit must be null or a number greater than or equal to 1","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"server/models/user.js","lineNumber":64,"sourceCode":"        return username;\n      } catch (e) {\n        throw new Error(e.message);\n      }\n    },\n    role: (role = \"default\") => {\n      const VALID_ROLES = [\"default\", \"admin\", \"manager\"];\n      if (!VALID_ROLES.includes(role)) {\n        throw new Error(\n          `Invalid role. Allowed roles are: ${VALID_ROLES.join(\", \")}`\n        );\n      }\n      return String(role);\n    },\n    dailyMessageLimit: (dailyMessageLimit = null) => {\n      if (dailyMessageLimit === null) return null;\n      const limit = Number(dailyMessageLimit);\n      if (isNaN(limit) || limit < 1) {\n        throw new Error(\n          \"Daily message limit must be null or a number greater than or equal to 1\"\n        );\n      }\n      return limit;\n    },\n    bio: (bio = \"\") => {\n      if (!bio || typeof bio !== \"string\") return \"\";\n      if (bio.length > 1000)\n        throw new Error(\"Bio cannot be longer than 1,000 characters\");\n      return String(bio);\n    },\n  },\n  // validations for the above writable fields.\n  castColumnValue: function (key, value) {\n    switch (key) {\n      case \"suspended\":\n        return Number(Boolean(value));\n      case \"dailyMessageLimit\":","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/models/user.js#L46-L82","documentation":"Thrown when dailyMessageLimit is not null and does not coerce to a number >= 1. null is the sentinel for \"no limit\"; 0, negatives, NaN-producing strings (\"abc\"), and the empty string all fail because Number(\"\") is 0. The validator runs before the Prisma write, so the whole update is rejected.","triggerScenarios":"user.update(userId, { dailyMessageLimit: 0 }) when intending \"unlimited\"; sending dailyMessageLimit: \"\" from an empty form input; passing \"ten\" or \"-5\"; passing fractional values below 1 such as 0.5.","commonSituations":"Multi-user admin limit forms that submit empty strings for untouched fields; scripts using 0 as the \"no limit\" sentinel; string/number coercion surprises from JSON payloads; frontend number inputs allowing 0.","solutions":["Send null (or omit the field) to remove the limit","Send an integer >= 1 to set a limit","Convert empty inputs to null client-side before submitting","Coerce with Number() and range-check before calling update"],"exampleFix":"// before\nawait user.update(userId, { dailyMessageLimit: \"\" });\n\n// after\nawait user.update(userId, { dailyMessageLimit: null }); // or a number >= 1","handlingStrategy":"validation","validationCode":"function normalizeLimit(v) {\n  if (v === null || v === undefined || v === \"\") return null; // null = unlimited\n  const n = Number(v);\n  if (Number.isNaN(n) || n < 1) {\n    return { error: \"Daily message limit must be null or a number >= 1\" };\n  }\n  return { value: n };\n}","typeGuard":"/** @param {unknown} v */\nfunction isValidDailyMessageLimit(v) {\n  if (v === null) return true;\n  if (typeof v === \"number\") return v >= 1;\n  if (typeof v === \"string\" && v !== \"\") {\n    const n = Number(v);\n    return !Number.isNaN(n) && n >= 1;\n  }\n  return false;\n}","tryCatchPattern":"try {\n  await user.update(userId, { dailyMessageLimit });\n} catch (e) {\n  if (/Daily message limit/i.test(e.message)) return res.status(400).json({ error: e.message });\n  throw e;\n}","preventionTips":["Use null for unlimited, never 0","Convert empty form fields to null before submit","Set min=1 on the number input and validate client-side"],"tags":["validation","numeric","rate-limit","user-management"],"backgroundTag":"invalid-numeric-range","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}