{"record":{"id":"5f02473a9560ecc8","repo":"lyswhut/lx-music-desktop","slug":"rule-key-max-length-no-match","errorCode":null,"errorMessage":"${rule.key} max length no match","messagePattern":"(.+?) max length no match","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/renderer/core/useApp/useDeeplink/utils.js","lineNumber":39,"sourceCode":"export 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":21,"sourceCodeEnd":46,"githubUrl":"https://github.com/lyswhut/lx-music-desktop/blob/9c364b482e5621a1d38b50e8610d2fb974457e6e/src/renderer/core/useApp/useDeeplink/utils.js#L21-L46","documentation":"dataVerify (utils.js:39) enforces a maximum character length via `String(val).length > rule.max`. When a field's string form exceeds its cap (e.g. name/singer max 200, img/url max 500-1024, ids max 64) it throws '<key> max length no match'. The check stringifies, so numbers are measured by their digit count.","triggerScenarios":"Any deep-link field whose string representation exceeds its declared max — a 300-character song name against max:200, a URL over 500/1024 chars, or a long albumName. The throw fires after the type check passes.","commonSituations":"Very long song/album/artist names from exotic metadata; injected or garbage data through an untrusted link; a URL with huge query params exceeding the 500/1024 caps.","solutions":["Truncate the field at the sender to the documented max before constructing the link.","Raise the rule's `max` if the larger size is legitimate for the field.","Pre-truncate values before calling dataVerify (e.g. name.slice(0, 200)).","Catch upstream and show which field overflowed via useDialog()."],"exampleFix":"// before\n      if (rule.max && String(val).length > rule.max) throw new Error(rule.key + ' max length no match')\n\n// after - include observed length and limit\n      if (rule.max && String(val).length > rule.max) {\n        throw new Error(`${rule.key} max length no match: ${String(val).length} > ${rule.max}`)\n      }","handlingStrategy":"validation","validationCode":"const findOverMax = (rules, data) =>\n  rules.filter(r => r.max && data[r.key] != null && String(data[r.key]).length > r.max).map(r => r.key)\nconst over = findOverMax(rules, data)\nif (over.length) {\n  showErrorDialog(`Field(s) too long: ${over.join(', ')}`)\n  return\n}","typeGuard":"const withinMax = (rule, data) => {\n  const v = data[rule.key]\n  return v == null || !rule.max || String(v).length <= rule.max\n}","tryCatchPattern":"try {\n  info = dataVerify(rules, info)\n} catch (e) {\n  errorDialog(e.message)\n}","preventionTips":["Truncate long fields (name/singer/img/url) at the sender to the documented caps.","Pre-truncate values before dataVerify when accepting untrusted links.","Note: utils.js:40 has a latent bug — the `min` check uses `>` instead of `<`; do not rely on it until fixed."],"tags":["deeplink","validation","length-limit","schema"],"backgroundTag":null,"analyzedSha":"9c364b482e5621a1d38b50e8610d2fb974457e6e","analyzedAt":"2026-08-12T15:14:48.244Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}