{"record":{"id":"3f3c2d4052ae2cd7","repo":"lyswhut/lx-music-desktop","slug":"error-3f3c2d","errorCode":null,"errorMessage":"获取评论失败","messagePattern":"获取评论失败","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/renderer/utils/musicSdk/mg/comment.js","lineNumber":14,"sourceCode":"import { httpFetch } from '../../request'\nimport getSongId from './songId'\nimport { dateFormat2 } from '../../index'\n\nexport default {\n  _requestObj: null,\n  _requestObj2: null,\n  _requestObj3: null,\n  lastCommentIds: new Map(),\n  async getComment(musicInfo, page = 1, limit = 20) {\n    if (this._requestObj) this._requestObj.cancelHttp()\n    if (!musicInfo.songId) {\n      let id = await getSongId(musicInfo)\n      if (!id) throw new Error('获取评论失败')\n      musicInfo.songId = id\n    }\n    if (page === 1) this.lastCommentIds.clear()\n    const lastCommentId = this.lastCommentIds.get(String(page)) || ''\n    if (!lastCommentId && page > 1) throw new Error('获取评论失败')\n    // const _requestObj = httpFetch(`https://music.migu.cn/v3/api/comment/listComments?targetId=${musicInfo.songId}&pageSize=${limit}&pageNo=${page}`, {\n    const _requestObj = httpFetch(`https://app.c.nf.migu.cn/MIGUM3.0/user/comment/stack/v1.0?pageSize=${limit}&queryType=1&resourceId=${musicInfo.songId}&resourceType=2&commentId=${lastCommentId}`, {\n      headers: {\n        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1',\n        // Referer: 'https://music.migu.cn',\n      },\n    })\n    const { body, statusCode } = await _requestObj.promise\n    // console.log(body)\n    if (statusCode != 200 || body.code !== '000000') throw new Error('获取评论失败')\n    const total = parseInt(body.data.commentNums)\n    const list = this.filterComment(body.data.comments)\n    this.lastCommentIds.set(String(page + 1), list.length ? list[list.length - 1].id : '')","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/lyswhut/lx-music-desktop/blob/9c364b482e5621a1d38b50e8610d2fb974457e6e/src/renderer/utils/musicSdk/mg/comment.js#L1-L32","documentation":"Thrown by Migu's getComment when getSongId(musicInfo) returns a falsy value. Migu uses a two-tier ID system (copyrightId vs songId/songmid), and getSongId resolves the real comment resource ID via getMusicInfo(copyrightId). If that lookup fails (returns null/undefined), there is no valid resource ID to query comments against, so the function aborts before making the HTTP request.","triggerScenarios":"Calling getComment(musicInfo) where musicInfo.songId is unset AND musicInfo.songmid equals musicInfo.copyrightId (meaning getSongId falls through to getMusicInfo). getMusicInfo fails or returns a record without a songmid field. This is a data/resolution error, not a network error — the HTTP request is never sent.","commonSituations":"The musicInfo object comes from a cached/stale search result where Migu has since removed the song. The copyrightId is invalid or was scraped incorrectly. getMusicInfo internally fails silently and returns an incomplete object.","solutions":["Ensure musicInfo already has songId populated before calling getComment to skip the resolution path entirely.","Debug getMusicInfo(copyrightId) independently to see what it returns for the failing song.","Validate that musicInfo.songmid differs from musicInfo.copyrightId or that getMusicInfo returns a valid songmid.","Catch this error in the caller and skip the song or show 'comments unavailable' instead of crashing the UI."],"exampleFix":"// before\nif (!musicInfo.songId) {\n  let id = await getSongId(musicInfo)\n  if (!id) throw new Error('获取评论失败')\n  musicInfo.songId = id\n}\n\n// after\nif (!musicInfo.songId) {\n  let id = await getSongId(musicInfo)\n  if (!id) {\n    console.warn('mg getComment: could not resolve songId for', musicInfo.copyrightId)\n    throw new Error('获取评论失败')\n  }\n  musicInfo.songId = id\n}","handlingStrategy":"validation","validationCode":"function hasResolvableSongId(musicInfo) {\n  if (musicInfo.songId) return true\n  // getSongId succeeds when songmid differs from copyrightId\n  return musicInfo.songmid && musicInfo.songmid !== musicInfo.copyrightId\n}","typeGuard":"function hasMiguSongId(musicInfo) {\n  return musicInfo != null && typeof musicInfo === 'object' && !!musicInfo.songId\n}","tryCatchPattern":"try {\n  if (!musicInfo.songId) musicInfo.songId = await getSongId(musicInfo)\n  if (!musicInfo.songId) throw new Error('获取评论失败')\n  const result = await mgComment.getComment(musicInfo, page, limit)\n} catch (err) {\n  if (err.message === '获取评论失败') {\n    console.warn('Migu songId unresolvable for', musicInfo.copyrightId)\n    return { source: 'mg', comments: [], total: 0, page, limit, maxPage: 1 }\n  }\n  throw err\n}","preventionTips":["Pre-populate musicInfo.songId before calling getComment to bypass the resolution path.","Debug getMusicInfo(copyrightId) independently to verify it returns a valid songmid.","Catch this error and skip the song rather than crashing the comments UI.","Share resolved songIds across getComment and getHotComment to avoid duplicate failures."],"tags":["migu","comments","song-id-resolution","data-validation"],"backgroundTag":null,"analyzedSha":"9c364b482e5621a1d38b50e8610d2fb974457e6e","analyzedAt":"2026-08-12T15:14:48.244Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}