From 2dfb09c51a6f1c4e45c2a072d33db49652b96c41 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Wed, 26 Jun 2024 03:46:25 -0700 Subject: [PATCH] Match convertRawProp error handling in iterator-based props parsing (#45156) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45156 We don't want to bubble up exceptions from props parsing, so match the behaviour from convertRawProp and fall back to the default value when an exception is encountered. Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D59000397 fbshipit-source-id: f6f64a80fed98525cdd2a5b5d360c2d6ede76a12 --- .../react/renderer/core/PropsMacros.h | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/core/PropsMacros.h b/packages/react-native/ReactCommon/react/renderer/core/PropsMacros.h index c3c352526b6..55fe5224dd0 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/PropsMacros.h +++ b/packages/react-native/ReactCommon/react/renderer/core/PropsMacros.h @@ -110,15 +110,19 @@ struct, blockStart, prefix "BlockStart" suffix, rawValue) // Rebuild a type that contains multiple fields from a single field value -#define REBUILD_FIELD_SWITCH_CASE( \ - defaults, rawValue, property, field, fieldName) \ - case CONSTEXPR_RAW_PROPS_KEY_HASH(fieldName): { \ - if ((rawValue).hasValue()) { \ - decltype((defaults).field) res; \ - fromRawValue(context, rawValue, res); \ - (property).field = res; \ - } else { \ - (property).field = (defaults).field; \ - } \ - return; \ +#define REBUILD_FIELD_SWITCH_CASE( \ + defaults, rawValue, property, field, fieldName) \ + case CONSTEXPR_RAW_PROPS_KEY_HASH(fieldName): { \ + if ((rawValue).hasValue()) [[likely]] { \ + try { \ + fromRawValue(context, rawValue, (property).field); \ + } catch (const std::exception& e) { \ + LOG(ERROR) << "Error while converting prop '" << fieldName \ + << "': " << e.what(); \ + (property).field = (defaults).field; \ + } \ + } else { \ + (property).field = (defaults).field; \ + } \ + return; \ }