{"record":{"id":"87ff7422f6307b78","repo":"mastra-ai/mastra","slug":"invalid-message-type","errorCode":null,"errorMessage":"Invalid message type","messagePattern":"Invalid message type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/playground-ui/src/lib/toast.tsx","lineNumber":31,"sourceCode":"// only built-in dismiss affordance we expose).\nexport const Toaster = ({ className, toastOptions, ...rest }: ToasterProps) => (\n  <SonnerToaster\n    {...rest}\n    closeButton\n    richColors\n    className={cn('mastra-toaster', className)}\n    toastOptions={{ duration: 5000, ...toastOptions }}\n  />\n);\n\n// Forward sonner's return value so callers can update/dismiss by id later.\nconst forEachOrOnce = <M, R>(message: M | M[], emit: (m: M) => R): R | R[] =>\n  Array.isArray(message) ? message.map(emit) : emit(message);\n\nexport const toast = (message: string | string[] | ReactNode, options: ExternalToast = {}) => {\n  if (Array.isArray(message)) return message.map(m => sonnerToast(m, options));\n  if (React.isValidElement(message) || typeof message === 'string') return sonnerToast(message, options);\n  throw new Error('Invalid message type');\n};\n\ntoast.success = (message: string | string[], options: ExternalToast = {}) =>\n  forEachOrOnce(message, m => sonnerToast.success(m, options));\ntoast.error = (message: string | string[], options: ExternalToast = {}) =>\n  forEachOrOnce(message, m => sonnerToast.error(m, options));\ntoast.warning = (message: string | string[], options: ExternalToast = {}) =>\n  forEachOrOnce(message, m => sonnerToast.warning(m, options));\ntoast.info = (message: string | string[], options: ExternalToast = {}) =>\n  forEachOrOnce(message, m => sonnerToast.info(m, options));\n\ntoast.custom = (message: ReactNode, options: ExternalToast = {}) => sonnerToast(message, options);\n\ntoast.dismiss = (toastId?: string | number) => sonnerToast.dismiss(toastId);\n\ntoast.promise = <T,>({\n  myPromise,\n  loadingMessage,","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/playground-ui/src/lib/toast.tsx#L13-L49","documentation":"The playground UI's toast() wrapper accepts a string, an array of strings, or a React element and forwards it to sonner. If the message is none of these (e.g. a plain object, number, null, or undefined), sonner cannot render it safely, so the wrapper throws 'Invalid message type' to surface the programming mistake early instead of showing a broken toast.","triggerScenarios":"Calling toast(message) where message is neither an array, nor a valid React element, nor a string — most commonly toast(undefined) when a variable holding the message is undefined, toast(err) with an Error object instead of err.message, or toast(someObject).","commonSituations":"Passing the result of a failed lookup (undefined) as the message, passing an Error/exception object directly rather than its .message, or passing a non-string value like a number or object from an API response.","solutions":["Ensure the value passed to toast() is a string (coerce with String(message ?? '') or message?.message for Errors).","If you have an Error, pass error.message rather than the Error object itself.","For rich content, pass an actual JSX element (<span>...</span>) which the wrapper accepts.","Check for undefined coming from optional API fields before calling toast and provide a default message."],"exampleFix":"// before\ntoast(error); // Error object — throws 'Invalid message type'\n\n// after\ntoast(error instanceof Error ? error.message : 'Something went wrong');","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isValidToastMessage(m: unknown): m is string | string[] | React.ReactElement {\n  return typeof m === 'string' || Array.isArray(m) || React.isValidElement(m);\n}","tryCatchPattern":"try {\n  toast(message as string);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Invalid message type') {\n    toast('Something went wrong'); // safe default\n  } else throw e;\n}","preventionTips":["Type toast message parameters as string | string[] | ReactNode at call sites.","Pass error.message, never the Error object itself.","Default undefined messages: toast(msg ?? 'Operation failed')."],"tags":["typescript","toast","developer-error","playground-ui"],"backgroundTag":"invalid-argument-type","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}