{"record":{"id":"5d993e002fc4408f","repo":"netdata/netdata","slug":"expected-a-digit-or-but-found-r-5d993e","errorCode":null,"errorMessage":"expected a digit or ' ', but found %r","messagePattern":"expected a digit or ' ', but found %r","errorType":"exception","errorClass":"ScannerError","httpStatus":null,"severity":"error","filePath":"src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py","lineNumber":841,"sourceCode":"        if ch not in '\\0 \\r\\n\\x85\\u2028\\u2029':\n            raise ScannerError(\"while scanning a directive\", start_mark,\n                    \"expected alphabetic or numeric character, but found %r\"\n                    % ch, self.get_mark())\n        return value\n\n    def scan_yaml_directive_value(self, start_mark):\n        # See the specification for details.\n        while self.peek() == ' ':\n            self.forward()\n        major = self.scan_yaml_directive_number(start_mark)\n        if self.peek() != '.':\n            raise ScannerError(\"while scanning a directive\", start_mark,\n                    \"expected a digit or '.', but found %r\" % self.peek(),\n                    self.get_mark())\n        self.forward()\n        minor = self.scan_yaml_directive_number(start_mark)\n        if self.peek() not in '\\0 \\r\\n\\x85\\u2028\\u2029':\n            raise ScannerError(\"while scanning a directive\", start_mark,\n                    \"expected a digit or ' ', but found %r\" % self.peek(),\n                    self.get_mark())\n        return (major, minor)\n\n    def scan_yaml_directive_number(self, start_mark):\n        # See the specification for details.\n        ch = self.peek()\n        if not ('0' <= ch <= '9'):\n            raise ScannerError(\"while scanning a directive\", start_mark,\n                    \"expected a digit, but found %r\" % ch, self.get_mark())\n        length = 0\n        while '0' <= self.peek(length) <= '9':\n            length += 1\n        value = int(self.prefix(length))\n        self.forward(length)\n        return value\n\n    def scan_tag_directive_value(self, start_mark):","sourceCodeStart":823,"sourceCodeEnd":859,"githubUrl":"https://github.com/netdata/netdata/blob/4864de85e26f6734d92cfc27ccbeff5921f49938/src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py#L823-L859","documentation":"Raised at the end of scan_yaml_directive_value: after the minor version number of a %YAML directive, only end-of-line, EOF, or a comment may follow. Trailing garbage after '%YAML 1.1' (extra token, letter, or dot) fails this check while scanning the directive.","triggerScenarios":"yaml.safe_load() on input with '%YAML 1.2 extra', '%YAML 1.1.1', '%YAML 1.1x' — anything after the minor number that is not whitespace-then-EOL/comment.","commonSituations":"Comments attached without '#': '%YAML 1.2 standard'; build scripts appending flags to the header line; a duplicated version token from templating.","solutions":["Put anything after the version on its own line or make it a comment: '%YAML 1.2  # standard'.","Remove trailing tokens so the directive line ends right after the minor number.","Re-validate the file parses."],"exampleFix":"# before\n%YAML 1.2 standard\n---\na: 1\n\n# after\n%YAML 1.2  # standard\n---\na: 1","handlingStrategy":"validation","validationCode":"import re\n\ndef no_trailing_after_version(text):\n    return all(re.match(r'^%YAML\\s+\\d+\\.\\d+(\\s*#.*)?\\s*$', l)\n               for l in text.splitlines() if l.startswith('%YAML'))","typeGuard":"def is_directive_tail_error(exc):\n    return isinstance(exc, yaml.scanner.ScannerError) and 'digit or' in str(exc) and 'directive' in str(exc)","tryCatchPattern":"try:\n    yaml.safe_load(text)\nexcept yaml.scanner.ScannerError as e:\n    report('nothing may follow the %YAML version except a # comment')","preventionTips":["Keep directives on their own single-purpose lines.","Comments after directives must start with '#'.","Automate header generation instead of hand-editing."],"tags":["yaml","python","directives","version","parsing"],"backgroundTag":null,"analyzedSha":"4864de85e26f6734d92cfc27ccbeff5921f49938","analyzedAt":"2026-08-15T09:12:38.226Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}