{"record":{"id":"3764b35359a491be","repo":"facebook/lexical","slug":"console-warn-error","errorCode":null,"errorMessage":"console.warn(error)","messagePattern":"console\\.warn\\(error\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/lexical/src/LexicalEditor.ts","lineNumber":517,"sourceCode":"};\n\nexport type Transform<T extends LexicalNode> = (node: T) => void;\n\nexport type ErrorHandler = (error: Error) => void;\n\n/**\n * Default {@link CreateEditorArgs.onWarn} handler. Used for recoverable,\n * warn-level conditions (e.g. the update-recursion guard tripping) that the\n * editor has already recovered from. Throws in development so the condition is\n * impossible to miss, and only `console.warn`s in production so it is not\n * reported as a fatal error. Embedders can override this via `onWarn` to route\n * the condition to their own telemetry at warn severity.\n */\nfunction defaultOnWarn(error: Error): void {\n  if (__DEV__) {\n    throw error;\n  }\n  console.warn(error);\n}\n\nexport type MutationListeners = Map<MutationListener, Set<Klass<LexicalNode>>>;\n\nexport type MutatedNodes = Map<Klass<LexicalNode>, Map<NodeKey, NodeMutation>>;\n\nexport type NodeMutation = 'created' | 'updated' | 'destroyed';\n\nexport interface MutationListenerOptions {\n  /**\n   * Skip the initial call of the listener with pre-existing DOM nodes.\n   *\n   * The default was previously true for backwards compatibility with <= 0.16.1\n   * but this default has been changed to false as of 0.21.0.\n   */\n  skipInitialization?: boolean;\n}\n","sourceCodeStart":499,"sourceCodeEnd":535,"githubUrl":"https://github.com/facebook/lexical/blob/76a22dcba981b46119fcec45f935270707e26a57/packages/lexical/src/LexicalEditor.ts#L499-L535","documentation":"defaultOnWarn is Lexical's default handler for recoverable problems routed through the editor's onWarn callback. In development (__DEV__) it throws to surface issues loudly; in production it only logs via console.warn so user-facing apps never crash on a warning.","triggerScenarios":"An editor warning is emitted and no custom onWarn was supplied to createEditor; in dev builds this propagates the error as a thrown exception at the point of detection.","commonSituations":"Seeing unexpected throws in dev mode for recoverable conditions; wanting warnings collected in telemetry instead of thrown; CI runs where dev-mode throws fail tests for benign issues.","solutions":["Fix the underlying condition named by the thrown error (dev throws carry the full message).","Supply onWarn in the editor config to route warnings to logging/telemetry instead of throwing: onWarn: (error) => console.error(error) or your reporter.","Suppress noise in tests by installing a permissive onWarn in test editors.","Only rely on prod behavior (console.warn) for end-user builds; do not treat prod warn silence as health."],"exampleFix":"// before\nconst editor = createEditor({ namespace: 'app' });\n// after\nconst editor = createEditor({\n  namespace: 'app',\n  onWarn: (error) => myTelemetry.warn(error.message),\n});","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  runEditorOperation(editor);\n} catch (e) {\n  if (__DEV__ && e instanceof Error && e.message.includes('Lexical')) {\n    myTelemetry.warn('Lexical dev warning thrown', e.message);\n  } else { throw e; }\n}","preventionTips":["Always configure onWarn in production apps for observability.","In tests, install a collecting onWarn to assert on warnings instead of crashes.","Treat dev throws as actionable: fix the root cause rather than suppressing."],"tags":["warnings","editor-config","dev-mode","error-handling"],"backgroundTag":"unhandled-editor-warning","analyzedSha":"76a22dcba981b46119fcec45f935270707e26a57","analyzedAt":"2026-08-31T21:45:54.792Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}