maotoumao/MusicFree · warning
toast.failToSharePlugin
Error message
toast.failToSharePlugin
What it means
This fallback toast appears when the 'Share plugin' option fails. Sharing is implemented by writing `plugin.instance.srcUrl` to the system clipboard via `Clipboard.setString(...)` from @react-native-clipboard/clipboard; any rejection (or the non-null-asserted srcUrl being unexpectedly absent) is caught and shown as 'failToSharePlugin' (preferring the error's own message).
Source
Thrown at src/pages/setting/settingTypes/pluginSetting/components/pluginItem.tsx:62
async onPress() {
try {
await pluginManager.updatePlugin(plugin);
Toast.success(t("toast.pluginUpdateSuccess"));
} catch (e: any) {
Toast.warn(e?.message ?? t("toast.failToUpdatePlugin"));
}
},
show: !!plugin.instance.srcUrl,
},
{
title: t("pluginSetting.pluginItem.options.sharePlugin"),
icon: "share",
async onPress() {
try {
Clipboard.setString(plugin.instance.srcUrl!);
Toast.success(t("toast.copiedToClipboard"));
} catch (e: any) {
Toast.warn(e?.message ?? t("toast.failToSharePlugin"));
}
},
show: !!plugin.instance.srcUrl,
},
{
title: t("pluginSetting.pluginItem.options.uninstallPlugin"),
icon: "trash-outline",
show: true,
onPress() {
showDialog("SimpleDialog", {
title: t("pluginSetting.pluginItem.options.uninstallPlugin"),
content: t("pluginSetting.pluginItem.options.uninstallPluginContent", {
name: plugin.name,
}),
async onOk() {
try {
await pluginManager.uninstallPlugin(plugin.hash);
Toast.success(t("toast.pluginUninstalled"));
View on GitHub (pinned to d118b18b3d)
Solutions
- Verify @react-native-clipboard/clipboard is installed and natively linked (rebuild the app / `npx pod-install` on iOS).
- Guard the srcUrl before calling the clipboard and surface a clearer message if it is missing.
- Retry the copy once — transient clipboard service failures occur on some devices.
- As a fallback, show the srcUrl in a dialog so the user can copy it manually.
Example fix
// before
Clipboard.setString(plugin.instance.srcUrl!);
// after
const url = plugin.instance.srcUrl;
if (typeof url !== "string" || !url) {
Toast.warn(t("toast.failToSharePlugin"));
return;
}
await Clipboard.setString(url); Defensive patterns
Strategy: validation
Validate before calling
const url = plugin.instance.srcUrl;
if (typeof url !== "string" || !url) {
Toast.warn(t("toast.failToSharePlugin"));
return;
}
await Clipboard.setString(url); Type guard
function hasShareableSrcUrl(p: Plugin): boolean {
return typeof p.instance.srcUrl === "string" && p.instance.srcUrl.length > 0;
} Try / catch
try {
await Clipboard.setString(plugin.instance.srcUrl!);
Toast.success(t("toast.copiedToClipboard"));
} catch (e: any) {
Toast.warn(e?.message ?? t("toast.failToSharePlugin"));
} Prevention
- Never rely on a truthiness check far above the usage — re-validate srcUrl right before the clipboard call.
- Keep @react-native-clipboard/clipboard linked and rebuild native code after upgrades.
- Offer a manual-copy fallback dialog when clipboard writes fail.
- Test clipboard operations on Android 10+ where background clipboard access is restricted.
When it happens
Trigger: Tapping the share option on a plugin (option is shown when `plugin.instance.srcUrl` is truthy) and `Clipboard.setString(plugin.instance.srcUrl!)` throws — e.g. the native clipboard module is unavailable, the promise rejects on certain OEM/Android versions, or srcUrl is undefined despite the truthiness check due to a stale plugin object.
Common situations: Missing or mismatched native clipboard dependency (new architecture/autolinking issues after RN upgrade); Android 10+ background clipboard restrictions in unusual contexts; emulator clipboard service quirks; corrupted plugin instance where srcUrl became null after a failed state update.
Related errors
AI-assisted analysis of maotoumao/MusicFree@d118b18b3d (2026-08-30).
Data as JSON: /api/errors/5a8e9f03a5289921.
Report an issue: GitHub.