Untitled conversation
- Usercode
unregisterPlugin(pluginKey) { const plugin = this._getPluginByKey(pluginKey); if (plugin) { plugin.detach?.(this.shadow.host); for (const rect of this.rects) { // togglePlugin(pluginClass) changed rect.togglePlugin(plugin, false); } this.allPlugins.delete(id); this.pluginContexts.delete(id); this.pluginIdMap.delete(id); this.scheduleRenderCSS(); } else { throw new PluginNotFoundError(this.unregisterPlugin, pluginKey); } } updatePluginOptions(pluginKey, options) { const plugin = this._getPluginByKey(pluginKey); if (plugin) { this.allPlugins.get(id).updateOptions?.(options); this.scheduleRenderCSS(); } else { throw new PluginNotFoundError(this.updatePluginOptions, pluginKey); } } _getPluginByKey(pluginKey) { const id = this.pluginIdMap.get(pluginKey); if (id) { return this.allPlugins.get(id); } } class PluginNotFoundError extends Error { constructor(functionRef, pluginIdentifier) { const functionName = functionRef.name || 'UnknownFunction'; let identifierString; if (typeof pluginIdentifier === 'symbol') { identifierString = pluginIdentifier.description || 'Symbol'; } else if (typeof pluginIdentifier === 'function') { identifierString = pluginIdentifier.pluginName || pluginIdentifier.name || 'UnnamedClass'; } else { identifierString = String(pluginIdentifier); } const message = `${functionName}: No plugin found for the identifier: "${identifierString}". Ensure the plugin is registered correctly and the identifier is valid.`; super(message); this.name = 'PluginNotFoundError'; } } - Assistant
To achieve what you want — encapsulating error handling within
this._getPluginByKeywhile ensuring the error stack reflects the call origin (i.e., the function that calls_getPluginByKey) — you can leverage JavaScript's error management capabilities. Specifically, you want to capture and throw the error within , but provide a mechanism to control the stack trace: - User
subtle issues because stack traces are often formatted differentlyso do you have better ways - Assistant