lyswhut/lx-music-desktop · error · Error

获取评论失败

Error message

获取评论失败

What it means

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.

Source

Thrown at src/renderer/utils/musicSdk/mg/comment.js:14

import { httpFetch } from '../../request'
import getSongId from './songId'
import { dateFormat2 } from '../../index'

export default {
  _requestObj: null,
  _requestObj2: null,
  _requestObj3: null,
  lastCommentIds: new Map(),
  async getComment(musicInfo, page = 1, limit = 20) {
    if (this._requestObj) this._requestObj.cancelHttp()
    if (!musicInfo.songId) {
      let id = await getSongId(musicInfo)
      if (!id) throw new Error('获取评论失败')
      musicInfo.songId = id
    }
    if (page === 1) this.lastCommentIds.clear()
    const lastCommentId = this.lastCommentIds.get(String(page)) || ''
    if (!lastCommentId && page > 1) throw new Error('获取评论失败')
    // const _requestObj = httpFetch(`https://music.migu.cn/v3/api/comment/listComments?targetId=${musicInfo.songId}&pageSize=${limit}&pageNo=${page}`, {
    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}`, {
      headers: {
        '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',
        // Referer: 'https://music.migu.cn',
      },
    })
    const { body, statusCode } = await _requestObj.promise
    // console.log(body)
    if (statusCode != 200 || body.code !== '000000') throw new Error('获取评论失败')
    const total = parseInt(body.data.commentNums)
    const list = this.filterComment(body.data.comments)
    this.lastCommentIds.set(String(page + 1), list.length ? list[list.length - 1].id : '')

View on GitHub (pinned to 9c364b482e)

Solutions

  1. Ensure musicInfo already has songId populated before calling getComment to skip the resolution path entirely.
  2. Debug getMusicInfo(copyrightId) independently to see what it returns for the failing song.
  3. Validate that musicInfo.songmid differs from musicInfo.copyrightId or that getMusicInfo returns a valid songmid.
  4. Catch this error in the caller and skip the song or show 'comments unavailable' instead of crashing the UI.

Example fix

// before
if (!musicInfo.songId) {
  let id = await getSongId(musicInfo)
  if (!id) throw new Error('获取评论失败')
  musicInfo.songId = id
}

// after
if (!musicInfo.songId) {
  let id = await getSongId(musicInfo)
  if (!id) {
    console.warn('mg getComment: could not resolve songId for', musicInfo.copyrightId)
    throw new Error('获取评论失败')
  }
  musicInfo.songId = id
}
Defensive patterns

Strategy: validation

Validate before calling

function hasResolvableSongId(musicInfo) {
  if (musicInfo.songId) return true
  // getSongId succeeds when songmid differs from copyrightId
  return musicInfo.songmid && musicInfo.songmid !== musicInfo.copyrightId
}

Type guard

function hasMiguSongId(musicInfo) {
  return musicInfo != null && typeof musicInfo === 'object' && !!musicInfo.songId
}

Try / catch

try {
  if (!musicInfo.songId) musicInfo.songId = await getSongId(musicInfo)
  if (!musicInfo.songId) throw new Error('获取评论失败')
  const result = await mgComment.getComment(musicInfo, page, limit)
} catch (err) {
  if (err.message === '获取评论失败') {
    console.warn('Migu songId unresolvable for', musicInfo.copyrightId)
    return { source: 'mg', comments: [], total: 0, page, limit, maxPage: 1 }
  }
  throw err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of lyswhut/lx-music-desktop@9c364b482e (2026-08-12). Data as JSON: /api/errors/3f3c2d4052ae2cd7. Report an issue: GitHub.