File tree Expand file tree Collapse file tree 2 files changed +63
-3
lines changed Expand file tree Collapse file tree 2 files changed +63
-3
lines changed Original file line number Diff line number Diff line change @@ -854,8 +854,13 @@ public function offsetGet($option)
854
854
// dependency
855
855
// BEGIN
856
856
$ this ->calling [$ option ] = true ;
857
- foreach ($ this ->lazy [$ option ] as $ closure ) {
858
- $ value = $ closure ($ this , $ value );
857
+ try {
858
+ foreach ($ this ->lazy [$ option ] as $ closure ) {
859
+ $ value = $ closure ($ this , $ value );
860
+ }
861
+ } catch (\Exception $ e ) {
862
+ unset($ this ->calling [$ option ]);
863
+ throw $ e ;
859
864
}
860
865
unset($ this ->calling [$ option ]);
861
866
// END
@@ -953,7 +958,12 @@ public function offsetGet($option)
953
958
// dependency
954
959
// BEGIN
955
960
$ this ->calling [$ option ] = true ;
956
- $ value = $ normalizer ($ this , $ value );
961
+ try {
962
+ $ value = $ normalizer ($ this , $ value );
963
+ } catch (\Exception $ e ) {
964
+ unset($ this ->calling [$ option ]);
965
+ throw $ e ;
966
+ }
957
967
unset($ this ->calling [$ option ]);
958
968
// END
959
969
}
Original file line number Diff line number Diff line change @@ -1103,6 +1103,56 @@ public function testFailIfCyclicDependencyBetweenNormalizerAndLazyOption()
1103
1103
$ this ->resolver ->resolve ();
1104
1104
}
1105
1105
1106
+ public function testCatchedExceptionFromNormalizerDoesNotCrashOptionResolver ()
1107
+ {
1108
+ $ throw = true ;
1109
+
1110
+ $ this ->resolver ->setDefaults (array ('catcher ' => null , 'thrower ' => null ));
1111
+
1112
+ $ this ->resolver ->setNormalizer ('catcher ' , function (Options $ options ) {
1113
+ try {
1114
+ return $ options ['thrower ' ];
1115
+ } catch (\Exception $ e ) {
1116
+ return false ;
1117
+ }
1118
+ });
1119
+
1120
+ $ this ->resolver ->setNormalizer ('thrower ' , function (Options $ options ) use (&$ throw ) {
1121
+ if ($ throw ) {
1122
+ $ throw = false ;
1123
+ throw new \UnexpectedValueException ('throwing ' );
1124
+ }
1125
+
1126
+ return true ;
1127
+ });
1128
+
1129
+ $ this ->resolver ->resolve ();
1130
+ }
1131
+
1132
+ public function testCatchedExceptionFromLazyDoesNotCrashOptionResolver ()
1133
+ {
1134
+ $ throw = true ;
1135
+
1136
+ $ this ->resolver ->setDefault ('catcher ' , function (Options $ options ) {
1137
+ try {
1138
+ return $ options ['thrower ' ];
1139
+ } catch (\Exception $ e ) {
1140
+ return false ;
1141
+ }
1142
+ });
1143
+
1144
+ $ this ->resolver ->setDefault ('thrower ' , function (Options $ options ) use (&$ throw ) {
1145
+ if ($ throw ) {
1146
+ $ throw = false ;
1147
+ throw new \UnexpectedValueException ('throwing ' );
1148
+ }
1149
+
1150
+ return true ;
1151
+ });
1152
+
1153
+ $ this ->resolver ->resolve ();
1154
+ }
1155
+
1106
1156
public function testInvokeEachNormalizerOnlyOnce ()
1107
1157
{
1108
1158
$ calls = 0 ;
You can’t perform that action at this time.
0 commit comments