{"record":{"id":"b3bbda0cce3eb245","repo":"netdata/netdata","slug":"expected-a-comment-or-a-line-break-but-found-r","errorCode":null,"errorMessage":"expected a comment or a line break, but found %r","messagePattern":"expected a comment or a line break, but found %r","errorType":"exception","errorClass":"ScannerError","httpStatus":null,"severity":"error","filePath":"src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py","lineNumber":896,"sourceCode":"    def scan_tag_directive_prefix(self, start_mark):\n        # See the specification for details.\n        value = self.scan_tag_uri('directive', start_mark)\n        ch = self.peek()\n        if ch not in '\\0 \\r\\n\\x85\\u2028\\u2029':\n            raise ScannerError(\"while scanning a directive\", start_mark,\n                    \"expected ' ', but found %r\" % ch, self.get_mark())\n        return value\n\n    def scan_directive_ignored_line(self, start_mark):\n        # See the specification for details.\n        while self.peek() == ' ':\n            self.forward()\n        if self.peek() == '#':\n            while self.peek() not in '\\0\\r\\n\\x85\\u2028\\u2029':\n                self.forward()\n        ch = self.peek()\n        if ch not in '\\0\\r\\n\\x85\\u2028\\u2029':\n            raise ScannerError(\"while scanning a directive\", start_mark,\n                    \"expected a comment or a line break, but found %r\"\n                        % ch, self.get_mark())\n        self.scan_line_break()\n\n    def scan_anchor(self, TokenClass):\n        # The specification does not restrict characters for anchors and\n        # aliases. This may lead to problems, for instance, the document:\n        #   [ *alias, value ]\n        # can be interpteted in two ways, as\n        #   [ \"value\" ]\n        # and\n        #   [ *alias , \"value\" ]\n        # Therefore we restrict aliases to numbers and ASCII letters.\n        start_mark = self.get_mark()\n        indicator = self.peek()\n        if indicator == '*':\n            name = 'alias'\n        else:","sourceCodeStart":878,"sourceCodeEnd":914,"githubUrl":"https://github.com/netdata/netdata/blob/4864de85e26f6734d92cfc27ccbeff5921f49938/src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py#L878-L914","documentation":"Raised by scan_directive_ignored_line: after a directive's value, only spaces, an optional '#' comment, and a line break may follow. Any other character — e.g. a stray token after '%YAML 1.1' or after a %TAG prefix — triggers this while scanning the directive. It is the generic 'garbage at end of directive line' guard.","triggerScenarios":"yaml.safe_load() on a file where a '%' directive line ends with non-comment, non-break content such as '%YAML 1.1 foo' or '%TAG ! !x 1'.","commonSituations":"Notes typed after directives assuming free text is allowed; sed/patch operations appending text to header lines without a newline.","solutions":["Delete everything after the directive value or convert it to a '#' comment on that line.","Confirm the directive line ends with a newline and nothing else.","Re-parse the document to verify the scanner passes the header."],"exampleFix":"# before\n%YAML 1.1 default encoding\n---\na: 1\n\n# after\n%YAML 1.1  # default encoding\n---\na: 1","handlingStrategy":"validation","validationCode":"import re\n\ndef directive_lines_clean(text):\n    for l in text.splitlines():\n        if l.startswith('%YAML'):\n            body = re.sub(r'\\s*#.*$', '', l).rstrip()\n            if re.fullmatch(r'%YAML\\s+\\d+\\.\\d+', body) is None:\n                return False\n        elif l.startswith('%TAG'):\n            body = re.sub(r'\\s*#.*$', '', l).rstrip()\n            if re.fullmatch(r'%TAG\\s+\\S+\\s+\\S+', body) is None:\n                return False\n    return True","typeGuard":"def is_ignored_line_error(exc):\n    return isinstance(exc, yaml.scanner.ScannerError) and 'comment or a line break' in str(exc)","tryCatchPattern":"try:\n    yaml.safe_load(text)\nexcept yaml.scanner.ScannerError as e:\n    report('directive line has trailing garbage; end it after the value')","preventionTips":["Treat directive lines as machine-written only.","Comments must use '#'.","Add a pre-load lint of every '%' line."],"tags":["yaml","python","directives","parsing","configuration"],"backgroundTag":null,"analyzedSha":"4864de85e26f6734d92cfc27ccbeff5921f49938","analyzedAt":"2026-08-15T09:12:38.226Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}