Internal changes.

PiperOrigin-RevId: 627188953
pull/16564/head
Protobuf Team Bot 2024-04-22 16:21:52 -07:00 committed by Copybara-Service
parent eaee04d897
commit 1a7aa2c4e8
1 changed files with 8 additions and 4 deletions

View File

@ -42,6 +42,10 @@ class VersionError(Exception):
"""Exception class for version violation."""
def _ReportVersionError(msg):
raise VersionError(msg)
def ValidateProtobufRuntimeVersion(
gen_domain, gen_major, gen_minor, gen_patch, gen_suffix, location
):
@ -76,28 +80,28 @@ def ValidateProtobufRuntimeVersion(
)
if gen_domain != DOMAIN:
raise VersionError(
_ReportVersionError(
'Detected mismatched Protobuf Gencode/Runtime domains when loading'
f' {location}: gencode {gen_domain.name} runtime {DOMAIN.name}.'
' Cross-domain usage of Protobuf is not supported.'
)
if gen_major != MAJOR:
raise VersionError(
_ReportVersionError(
'Detected mismatched Protobuf Gencode/Runtime major versions when'
f' loading {location}: gencode {gen_version} runtime {version}.'
f' Same major version is required. {error_prompt}'
)
if MINOR < gen_minor or (MINOR == gen_minor and PATCH < gen_patch):
raise VersionError(
_ReportVersionError(
'Detected incompatible Protobuf Gencode/Runtime versions when loading'
f' {location}: gencode {gen_version} runtime {version}. Runtime version'
f' cannot be older than the linked gencode version. {error_prompt}'
)
if gen_suffix != SUFFIX:
raise VersionError(
_ReportVersionError(
'Detected mismatched Protobuf Gencode/Runtime version suffixes when'
f' loading {location}: gencode {gen_version} runtime {version}.'
f' Version suffixes must be the same. {error_prompt}'