{"record":{"id":"1d47c5e6cca4a887","repo":"maotoumao/MusicFree","slug":"panel-addtomusicsheet-toast-fail","errorCode":null,"errorMessage":"panel.addToMusicSheet.toast.fail","messagePattern":"panel\\.addToMusicSheet\\.toast\\.fail","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/components/panels/types/addToMusicSheet.tsx","lineNumber":65,"sourceCode":"                            }}\r\n                            ListHeaderComponent={\r\n                                <ListItem\r\n                                    withHorizontalPadding\r\n                                    key=\"new\"\r\n                                    onPress={() => {\r\n                                        showPanel(\"CreateMusicSheet\", {\r\n                                            defaultName: newSheetDefaultName,\r\n                                            async onSheetCreated(sheetId) {\r\n                                                try {\r\n                                                    await MusicSheet.addMusic(\r\n                                                        sheetId,\r\n                                                        musicItem,\r\n                                                    );\r\n                                                    Toast.success(\r\n                                                        t(\"panel.addToMusicSheet.toast.success\"),\r\n                                                    );\r\n                                                } catch {\r\n                                                    Toast.warn(\r\n                                                        t(\"panel.addToMusicSheet.toast.fail\"),\r\n                                                    );\r\n                                                }\r\n                                            },\r\n                                            onCancel() {\r\n                                                showPanel(\"AddToMusicSheet\", {\r\n                                                    musicItem: musicItem,\r\n                                                    newSheetDefaultName,\r\n                                                });\r\n                                            },\r\n                                        });\r\n                                    }}>\r\n                                    <ListItem.ListItemImage\r\n                                        fallbackImg={ImgAsset.add}\r\n                                    />\r\n                                    <ListItem.Content title={t(\"panel.addToMusicSheet.newMusicSheet\")} />\r\n                                </ListItem>\r\n                            }\r","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/maotoumao/MusicFree/blob/d118b18b3d0c904400f7eea7bf99c0ceec6c1aee/src/components/panels/types/addToMusicSheet.tsx#L47-L83","documentation":"When the user confirms creating a new music sheet from the AddToMusicSheet panel, `onSheetCreated` calls the music sheet API to create the sheet and add the track inside a try/catch. On any rejection the panel shows the localized failure toast `panel.addToMusicSheet.toast.fail`. It means sheet creation or the add-to-sheet operation failed (storage, duplicate, or plugin/data error), not a crash.","triggerScenarios":"CreateMusicSheet dialog's onOk creates a sheet with a name that already exists or is empty/invalid, the underlying storage write (MMKV/async storage) rejects, or the addMusicToSheet call fails for the collected musicItem(s), causing the catch branch to fire.","commonSituations":"User enters a duplicate sheet name; device storage is full or storage permission issues corrupt the persistence layer; adding a track whose musicItem lacks required fields (id/title/artist) from a broken plugin; concurrent sheet creation races.","solutions":["Use a unique, non-empty sheet name — duplicates typically reject creation.","Retry the operation; if it persists, restart the app to reinitialize the music-sheet store.","Verify the track itself plays correctly first; a malformed musicItem from a faulty plugin can fail the add step — update or disable that plugin.","Check device storage availability and app data permissions if failures are consistent.","If the sheet was created but the toast still shows fail, open the sheet list to confirm state before retrying to avoid duplicates."],"exampleFix":"// before: adding a track with a missing id from a broken plugin\nawait addMusicToSheet(createdSheetId, musicItem);\n\n// after: validate first\nif (!musicItem?.id || !musicItem?.title || !musicItem?.artist) {\n    Toast.warn('歌曲信息不完整，无法添加');\n    return;\n}\nawait addMusicToSheet(createdSheetId, musicItem);","handlingStrategy":"validation","validationCode":"import { useMusicSheetStore } from '@/store/musicSheet';\n\nasync function validateSheetName(name: string) {\n    const trimmed = name.trim();\n    if (!trimmed) return '歌单名不能为空';\n    if (useMusicSheetStore.getState().musicSheets.some(s => s.title === trimmed)) {\n        return '歌单名已存在';\n    }\n    return null;\n}\n\nconst err = await validateSheetName(sheetName);\nif (err) {\n    Toast.warn(err);\n    return;\n}\n// proceed with create + addMusicToSheet","typeGuard":"function isValidMusicItem(item: IMusicItem | null | undefined):\n    item is IMusicItem {\n    return !!item && typeof item.id !== 'undefined'\n        && typeof item.title === 'string' && item.title.length > 0\n        && typeof item.artist === 'string';\n}","tryCatchPattern":"try {\n    const sheetId = await MusicSheetApi.createMusicSheet(name);\n    await MusicSheetApi.addMusicToSheet(sheetId, musicItem);\n    Toast.success(t('panel.addToMusicSheet.toast.success'));\n} catch (e) {\n    console.warn('addToMusicSheet failed', e);\n    Toast.warn(t('panel.addToMusicSheet.toast.fail'));\n}","preventionTips":["Enforce unique, non-empty sheet names in the CreateMusicSheet dialog before submission.","Validate musicItem fields (id, title, artist) before adding tracks sourced from plugins.","Check storage availability if persistence writes fail repeatedly.","Show distinct messages for 'create failed' vs 'add failed' to make diagnosis easier for users."],"tags":["storage","music-sheet","i18n","validation"],"backgroundTag":"sheet-creation-failed","analyzedSha":"d118b18b3d0c904400f7eea7bf99c0ceec6c1aee","analyzedAt":"2026-08-30T11:49:12.932Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}