Skip to content

Commit 2fcafab

Browse files
authored
Catch TypeError if google/protobuf ^4.31 and ext-protobuf <4.31 are installed (#1598)
1 parent 389fa3f commit 2fcafab

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Contrib/Otlp/ProtobufSerializer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ private static function serializeToJsonString(Message $message): string
102102
{
103103
// @phan-suppress-next-line PhanUndeclaredClassReference
104104
if (\class_exists(\Google\Protobuf\PrintOptions::class)) {
105-
/** @psalm-suppress TooManyArguments @phan-suppress-next-line PhanParamTooManyInternal,PhanUndeclaredClassConstant @phpstan-ignore arguments.count */
106-
return $message->serializeToJsonString(\Google\Protobuf\PrintOptions::ALWAYS_PRINT_ENUMS_AS_INTS);
105+
try {
106+
/** @psalm-suppress TooManyArguments @phan-suppress-next-line PhanParamTooManyInternal,PhanUndeclaredClassConstant @phpstan-ignore arguments.count */
107+
return $message->serializeToJsonString(\Google\Protobuf\PrintOptions::ALWAYS_PRINT_ENUMS_AS_INTS);
108+
} catch (\TypeError) {
109+
// google/protobuf ^4.31 w/ ext-protobuf <4.31 installed
110+
}
107111
}
108112

109113
$payload = $message->serializeToJsonString();

0 commit comments

Comments
 (0)