maotoumao/MusicFree · info

toast.copiedToClipboardFailed

Error message

toast.copiedToClipboardFailed

What it means

Toast shown when copying an artist name to the clipboard fails. onPress calls Clipboard.setString(musicItem.artist.toString()) inside try/catch; if the native clipboard API rejects (null/unavailable clipboard module, weird string content) the catch shows this warning.

Source

Thrown at src/components/panels/types/musicItemOptions.tsx:89

                            platform: musicItem.platform,
                            id: musicItem.id,
                        },
                        null,
                        "",
                    ),
                );
                Toast.success(t("toast.copiedToClipboard"));
            },
        },
        {
            icon: "user",
            title: t("panel.musicItemOptions.author", { artist: musicItem.artist }),
            onPress: () => {
                try {
                    Clipboard.setString(musicItem.artist.toString());
                    Toast.success(t("toast.copiedToClipboard"));
                } catch {
                    Toast.warn(t("toast.copiedToClipboardFailed"));
                }
            },
        },
        {
            icon: "album-outline",
            show: !!musicItem.album,
            title: t("panel.musicItemOptions.album", { album: musicItem.album }),
            onPress: () => {
                try {
                    Clipboard.setString(musicItem.album.toString());
                    Toast.success(t("toast.copiedToClipboard"));
                } catch {
                    Toast.warn(t("toast.copiedToClipboardFailed"));
                }
            },
        },
        {
            icon: "motion-play",

View on GitHub (pinned to d118b18b3d)

Solutions

  1. Verify the clipboard native module is linked (rebuild the app after installing @react-native-clipboard/clipboard)
  2. Ensure musicItem.artist is a plain string or number before copying
  3. Add a platform check and disable copy options where clipboard is unsupported

Example fix

// before
Clipboard.setString(musicItem.artist.toString());
// after
const artistText = typeof musicItem.artist === 'string' ? musicItem.artist : String(musicItem.artist ?? '');
if (artistText) Clipboard.setString(artistText);
Defensive patterns

Strategy: try-catch

Validate before calling

if (musicItem?.artist == null) return;

Type guard

function hasCopyableArtist(m: any): m is IMusicItem {
    return m?.artist != null && ['string','number'].includes(typeof m.artist);
}

Try / catch

try {
    Clipboard.setString(String(musicItem.artist));
    Toast.success(t('toast.copiedToClipboard'));
} catch {
    Toast.warn(t('toast.copiedToClipboardFailed'));
}

Prevention

When it happens

Trigger: Tapping 'copy artist' when Clipboard.setString throws — react-native clipboard module unavailable in the current environment (e.g. web/Windows port without implementation) or the value cannot be serialized.

Common situations: Running on a platform where @react-native-clipboard/clipboard is not linked; musicItem.artist is an unusual object whose toString throws; headless/test environment without clipboard support.

Related errors


AI-assisted analysis of maotoumao/MusicFree@d118b18b3d (2026-08-30). Data as JSON: /api/errors/6b5e07d6ee97edd0. Report an issue: GitHub.