{"record":{"id":"00ffd49709e1586e","repo":"lyswhut/lx-music-desktop","slug":"rule-key-type-no-match","errorCode":null,"errorMessage":"${rule.key} type no match","messagePattern":"(.+?) type no match","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/renderer/core/useApp/useDeeplink/utils.js","lineNumber":38,"sourceCode":"\nexport const qualitys = ['128k', '320k', 'flac', 'flac24bit']\nexport const qualityFilter = (source, types) => {\n  types = types.filter(({ type }) => qualitys.includes(type)).map(({ type, size, hash }) => {\n    if (size != null && typeof size != 'string') throw new Error(type + ' size type no match')\n    if (source == 'kg' && typeof hash != 'string') throw new Error(type + ' hash type no match')\n    return hash == null ? { type, size } : { type, size, hash }\n  })\n  if (!types.length) throw new Error('quality no match')\n  return types\n}\n\nexport const dataVerify = (rules, data) => {\n  const newData = {}\n  for (const rule of rules) {\n    const val = data[rule.key]\n    if (rule.required && val == null) throw new Error(rule.key + ' missing')\n    if (val != null) {\n      if (rule.types && !rule.types.includes(typeof val)) throw new Error(rule.key + ' type no match')\n      if (rule.max && String(val).length > rule.max) throw new Error(rule.key + ' max length no match')\n      if (rule.min && String(val).length > rule.min) throw new Error(rule.key + ' min length no match')\n    }\n    newData[rule.key] = val\n  }\n  return newData\n}\n","sourceCodeStart":20,"sourceCodeEnd":46,"githubUrl":"https://github.com/lyswhut/lx-music-desktop/blob/9c364b482e5621a1d38b50e8610d2fb974457e6e/src/renderer/core/useApp/useDeeplink/utils.js#L20-L46","documentation":"dataVerify (utils.js:38) checks each non-null value's `typeof` against the rule's `types` array. A mismatch throws '<key> type no match'. For example, a `types` field sent as a string instead of an object, or `interval` as a number when only ['string'] is permitted, trips this guard.","triggerScenarios":"A field whose runtime type is not in the allowed set — e.g. musicInfo.types is a JSON string rather than an array/object; songInterval is a number but the rule only lists 'string'. Note: typeof for arrays/objects is both 'object', so array-vs-object is not distinguished here.","commonSituations":"Loosely-typed JSON where the sender used a different primitive; numeric fields sent as strings when the rule only allows 'number' (many rules defensively allow both 'string' and 'number'); a field double-encoded as a stringified JSON.","solutions":["Align the sender's primitive type with the rule's `types` array.","Broaden the rule (e.g. add 'number') if both primitives are acceptable for that field.","Coerce the value to an accepted type before validation.","Inspect the interpolated key name to find the exact field, then check its rule in useMusicAction.js/useSonglistAction.js."],"exampleFix":"// before\n      if (rule.types && !rule.types.includes(typeof val)) throw new Error(rule.key + ' type no match')\n\n// after - report observed vs expected for faster diagnosis\n      if (rule.types && !rule.types.includes(typeof val)) {\n        throw new Error(`${rule.key} type no match: got ${typeof val}, expected one of ${rule.types.join(', ')}`)\n      }","handlingStrategy":"validation","validationCode":"const findTypeMismatches = (rules, data) =>\n  rules.filter(r => data[r.key] != null && r.types && !r.types.includes(typeof data[r.key])).map(r => r.key)\nconst bad = findTypeMismatches(rules, data)\nif (bad.length) {\n  showErrorDialog(`Wrong type for field(s): ${bad.join(', ')}`)\n  return\n}","typeGuard":"const matchesRuleType = (rule, data) => {\n  const v = data[rule.key]\n  return v == null || !rule.types || rule.types.includes(typeof v)\n}","tryCatchPattern":"try {\n  info = dataVerify(rules, info)\n} catch (e) {\n  errorDialog(e.message)\n}","preventionTips":["Coerce fields to an accepted primitive at the boundary (e.g. String(interval)) when the sender's type differs.","Where both string and number are fine, list both in the rule's `types`.","Inspect the interpolated key to find the offending field fast."],"tags":["deeplink","validation","type-coercion","schema"],"backgroundTag":null,"analyzedSha":"9c364b482e5621a1d38b50e8610d2fb974457e6e","analyzedAt":"2026-08-12T15:14:48.244Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}