diff --git a/python/google/protobuf/runtime_version.py b/python/google/protobuf/runtime_version.py index bc4061cfeb..7f294b36fb 100644 --- a/python/google/protobuf/runtime_version.py +++ b/python/google/protobuf/runtime_version.py @@ -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}'