MCPcopy Index your code
hub / github.com/python/cpython / TOMLDecodeError

Class TOMLDecodeError

Lib/tomllib/_parser.py:64–122  ·  view source on GitHub ↗

An error raised if a document is not valid TOML. Adds the following attributes to ValueError: msg: The unformatted error message doc: The TOML document being parsed pos: The index of doc where parsing failed lineno: The line corresponding to pos colno: The column correspondi

Source from the content-addressed store, hash-verified

62
63
64class TOMLDecodeError(ValueError):
65 """An error raised if a document is not valid TOML.
66
67 Adds the following attributes to ValueError:
68 msg: The unformatted error message
69 doc: The TOML document being parsed
70 pos: The index of doc where parsing failed
71 lineno: The line corresponding to pos
72 colno: The column corresponding to pos
73 """
74
75 def __init__(
76 self,
77 msg: str = DEPRECATED_DEFAULT, # type: ignore[assignment]
78 doc: str = DEPRECATED_DEFAULT, # type: ignore[assignment]
79 pos: Pos = DEPRECATED_DEFAULT, # type: ignore[assignment]
80 *args: Any,
81 ):
82 if (
83 args
84 or not isinstance(msg, str)
85 or not isinstance(doc, str)
86 or not isinstance(pos, int)
87 ):
88 import warnings
89
90 warnings.warn(
91 "Free-form arguments for TOMLDecodeError are deprecated. "
92 "Please set 'msg' (str), 'doc' (str) and 'pos' (int) arguments only.",
93 DeprecationWarning,
94 stacklevel=2,
95 )
96 if pos is not DEPRECATED_DEFAULT: # type: ignore[comparison-overlap]
97 args = pos, *args
98 if doc is not DEPRECATED_DEFAULT: # type: ignore[comparison-overlap]
99 args = doc, *args
100 if msg is not DEPRECATED_DEFAULT: # type: ignore[comparison-overlap]
101 args = msg, *args
102 ValueError.__init__(self, *args)
103 return
104
105 lineno = doc.count("\n", 0, pos) + 1
106 if lineno == 1:
107 colno = pos + 1
108 else:
109 colno = pos - doc.rindex("\n", 0, pos)
110
111 if pos >= len(doc):
112 coord_repr = "end of document"
113 else:
114 coord_repr = f"line {lineno}, column {colno}"
115 errmsg = f"{msg} (at {coord_repr})"
116 ValueError.__init__(self, errmsg)
117
118 self.msg = msg
119 self.doc = doc
120 self.pos = pos
121 self.lineno = lineno

Callers 13

loadsFunction · 0.85
skip_untilFunction · 0.85
create_dict_ruleFunction · 0.85
create_list_ruleFunction · 0.85
key_value_ruleFunction · 0.85
parse_key_value_pairFunction · 0.85
parse_key_partFunction · 0.85
parse_arrayFunction · 0.85
parse_inline_tableFunction · 0.85
parse_basic_str_escapeFunction · 0.85
parse_hex_charFunction · 0.85
parse_basic_strFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…