{"record":{"id":"2fdbfc26c6efe2e6","repo":"matplotlib/matplotlib","slug":"srcset-argument-entry-is-invalid","errorCode":null,"errorMessage":"srcset argument \"{entry}\" is invalid.","messagePattern":"srcset argument \"(.+?)\" is invalid\\.","errorType":"exception","errorClass":"ExtensionError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/sphinxext/figmpl_directive.py","lineNumber":127,"sourceCode":"\n        return [image_node]\n\n\ndef _parse_srcsetNodes(st):\n    \"\"\"\n    parse srcset...\n    \"\"\"\n    entries = st.split(',')\n    srcset = {}\n    for entry in entries:\n        spl = entry.strip().split(' ')\n        if len(spl) == 1:\n            srcset[0] = spl[0]\n        elif len(spl) == 2:\n            mult = spl[1][:-1]\n            srcset[float(mult)] = spl[0]\n        else:\n            raise ExtensionError(f'srcset argument \"{entry}\" is invalid.')\n    return srcset\n\n\ndef _copy_images_figmpl(self, node):\n\n    # these will be the temporary place the plot-directive put the images eg:\n    # ../../../build/html/plot_directive/users/explain/artists/index-1.png\n    if node['srcset']:\n        srcset = _parse_srcsetNodes(node['srcset'])\n    else:\n        srcset = None\n\n    # the rst file's location:  eg /Users/username/matplotlib/doc/users/explain/artists\n    docsource = PurePath(self.document['source']).parent\n\n    # get the relpath relative to root:\n    srctop = self.builder.srcdir\n    rel = relpath(docsource, srctop).replace('.', '').replace(os.sep, '-')","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/sphinxext/figmpl_directive.py#L109-L145","documentation":"matplotlib's figmpl Sphinx directive builds an HTML <img srcset> for HiDPI figures. Its :srcset: option is a comma-separated list where each entry must be either a bare image path or exactly two space-separated tokens ('path multiplier'). An entry that splits into three or more tokens - or otherwise is not a 1-2 field entry - raises this ExtensionError and aborts the Sphinx build at the directive.","triggerScenarios":"Writing :srcset: fig-1.png 2.0x stray under a figmpl directive (three tokens); image paths containing unquoted spaces (each space adds a token); forgetting the comma between two entries so they merge into one multi-token entry.","commonSituations":"Hand-editing figmpl directives in matplotlib-based docs; copying browser HTML srcset syntax (which allows descriptors and commas per URL, unlike this option); CI doc builds that only fail after the srcset option was added.","solutions":["Reformat each entry to 'path multiplier' form, e.g. :srcset: fig-1.png 2.0x","Separate multiple entries with commas and remove stray tokens","Rename or quote image paths that contain spaces"],"exampleFix":"# before (RST)\n.. figmpl:: myfig.png\n   :srcset: myfig-1.png 2.0x extra-token\n\n# after (RST)\n.. figmpl:: myfig.png\n   :srcset: myfig-1.png 2.0x","handlingStrategy":"validation","validationCode":"import re\n\ndef valid_figmpl_srcset(option: str) -> bool:\n    \"\"\"Each comma-separated entry: bare path, or 'path mult' with a float+x.\"\"\"\n    for entry in option.split(','):\n        tokens = entry.strip().split(' ')\n        if not 1 <= len(tokens) <= 2:\n            return False\n        if len(tokens) == 2 and not re.fullmatch(r'[+-]?(\\d+\\.?\\d*|\\.\\d+)([eE][+-]?\\d+)?x', tokens[1]):\n            return False\n    return True\n\nassert valid_figmpl_srcset('myfig-1.png 2.0x'), 'fix the :srcset: option'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep each :srcset: entry to exactly 'path multiplier' pairs separated by commas","Avoid spaces in image paths referenced by figmpl directives","Run sphinx-build locally (including -W) before pushing doc changes"],"tags":["matplotlib","sphinx","figmpl","srcset","doc-build","extensionerror"],"backgroundTag":"invalid-srcset-syntax","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}