maotoumao/MusicFree · warning
toast.failToImportMusic
Error message
toast.failToImportMusic
What it means
This warning toast is shown when importing a single music item via a plugin yields no usable result. After the user enters a URL/text in the SimpleInput panel, the code awaits `plugin.methods.importMusicItem(text)`; if the resolved value is falsy (null/undefined/empty), it warns 'failToImportMusic'. The plugin itself is expected to resolve a shared link into an IMusicItem; a falsy return means the plugin could not resolve it.
Source
Thrown at src/pages/setting/settingTypes/pluginSetting/components/pluginItem.tsx:140
text,
);
if (result) {
showDialog("SimpleDialog", {
title: t("pluginSetting.pluginItem.options.importDialogTitle"),
content: t("pluginSetting.pluginItem.options.importMusicDialogContent", {
name: result.title,
}),
onOk() {
showPanel("AddToMusicSheet", {
musicItem: result,
newSheetDefaultName: t("pluginSetting.pluginItem.options.importMusicToSheetName", {
name: plugin.name,
}),
});
},
});
} else {
Toast.warn(t("toast.failToImportMusic"));
}
},
});
},
show: !!plugin.supportedMethods.has("importMusicItem"),
},
{
title: t("pluginSetting.pluginItem.options.importSheet"),
icon: "arrow-right-end-on-rectangle",
onPress() {
showPanel("SimpleInput", {
title: t("pluginSetting.pluginItem.options.importSheet"),
placeholder: t("pluginSetting.pluginItem.options.importSheetPlaceHolder"),
hints: plugin.instance.hints?.importMusicSheet,
maxLength: 1000,
async onOk(text, closePanel) {
Toast.success(t("toast.importing"));
closePanel();
View on GitHub (pinned to d118b18b3d)
Solutions
- Verify the pasted URL matches the formats documented in the plugin's `hints.importMusicItem` (shown as panel hints) and re-enter it.
- Check network connectivity and retry — remote resolution inside the plugin may have failed silently.
- Update the plugin to its latest version; older versions break when the source service changes its share-link format or API.
- If the plugin requires auth, set its user variables (userVariables panel) with valid cookies/tokens.
Example fix
// before
const result = await plugin.methods.importMusicItem(text);
if (result) { ... } else {
Toast.warn(t("toast.failToImportMusic"));
}
// after
let result;
try {
result = await plugin.methods.importMusicItem(text);
} catch (e: any) {
Toast.warn(e?.message ?? t("toast.failToImportMusic"));
return;
}
if (result && result.id) { ... } else {
Toast.warn(t("toast.failToImportMusic"));
} Defensive patterns
Strategy: validation
Validate before calling
const result = await plugin.methods.importMusicItem(text);
if (!result || typeof result !== "object" || !result.id || !result.title) {
Toast.warn(t("toast.failToImportMusic"));
return;
} Type guard
function isMusicItem(x: unknown): x is IMusicItem {
return !!x && typeof x === "object" && typeof (x as any).id !== "undefined" && typeof (x as any).title === "string";
} Try / catch
try {
const result = await plugin.methods.importMusicItem(text);
if (!isMusicItem(result)) throw new Error("invalid result");
// proceed
} catch (e: any) {
Toast.warn(e?.message ?? t("toast.failToImportMusic"));
} Prevention
- Follow the format hints shown in the import panel (plugin.instance.hints.importMusicItem).
- Validate the plugin result shape before opening downstream dialogs.
- Keep plugins updated — share-link parsers break when platforms change.
- Set required plugin user variables (cookies/tokens) for services that need auth.
When it happens
Trigger: Submitting the import-music panel with text that the plugin's `importMusicItem` cannot resolve: an unsupported URL/host, a private or deleted track, an invalid share-code format, or the plugin returning null on any internal error. Also note any rejection here is unhandled (no try/catch around the await), so only falsy results reach this toast.
Common situations: Pasting a link from a music service the plugin doesn't support; sharing an expired or region-locked link; network failure inside the plugin causing it to return null; plugin's user variables (e.g. cookies/tokens) missing or expired; typos in a manually entered song ID.
Related errors
AI-assisted analysis of maotoumao/MusicFree@d118b18b3d (2026-08-30).
Data as JSON: /api/errors/ee1d53ab88b278ff.
Report an issue: GitHub.