MCPcopy
hub / github.com/psycopg/psycopg / fetch_errors

Function fetch_errors

tools/update_errors.py:82–133  ·  view source on GitHub ↗
(versions)

Source from the content-addressed store, hash-verified

80
81
82def fetch_errors(versions):
83 classes = {}
84 errors = defaultdict(dict)
85
86 for version in versions:
87 logger.info("fetching errors from version %s", version)
88 tag = tag_from_version(version)
89 url = (
90 "https://raw.githubusercontent.com/postgres/postgres"
91 f"/refs/heads/{tag}/src/backend/utils/errcodes.txt"
92 )
93 c1, e1 = parse_errors_txt(url)
94 classes.update(c1)
95
96 for c, cerrs in e1.items():
97 errors[c].update(cerrs)
98
99 # clean up data
100
101 # success and warning - never raised
102 del classes["00"]
103 del classes["01"]
104 del errors["00"]
105 del errors["01"]
106
107 specific = {
108 "38002": "ModifyingSqlDataNotPermittedExt",
109 "38003": "ProhibitedSqlStatementAttemptedExt",
110 "38004": "ReadingSqlDataNotPermittedExt",
111 "39004": "NullValueNotAllowedExt",
112 "XX000": "InternalError_",
113 }
114
115 seen = set("""
116 Error Warning InterfaceError DataError DatabaseError ProgrammingError
117 IntegrityError InternalError NotSupportedError OperationalError
118 """.split())
119
120 for c, cerrs in errors.items():
121 for sqstate, errlabel in list(cerrs.items()):
122 if sqstate in specific:
123 clsname = specific[sqstate]
124 else:
125 clsname = errlabel.title().replace("_", "")
126 if clsname in seen:
127 raise Exception("class already existing: %s" % clsname)
128 seen.add(clsname)
129
130 basename = get_base_exception(sqstate).__name__
131 cerrs[sqstate] = Error(sqstate, errlabel, clsname, basename)
132
133 return classes, errors
134
135
136def generate_module_data(classes, errors):

Callers 1

mainFunction · 0.85

Calls 6

get_base_exceptionFunction · 0.90
tag_from_versionFunction · 0.85
parse_errors_txtFunction · 0.85
ErrorClass · 0.85
addMethod · 0.80
infoMethod · 0.45

Tested by

no test coverage detected