Skip to content

Commit f823221

Browse files
adinauerclaude
andcommitted
ref(sentry): Extract JsonObjectReader recovery helper
Move the repeated recovery logging flow behind a dedicated helper so the collection readers stay focused on parsing and keep the guarded recovery behavior aligned across all three paths. This does not change behavior. It only removes duplicated error handling around failed value recovery. Refs GH-5278 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1f8edab commit f823221

1 file changed

Lines changed: 38 additions & 24 deletions

File tree

sentry/src/main/java/io/sentry/JsonObjectReader.java

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,13 @@ public void nextUnknown(ILogger logger, Map<String, Object> unknown, String name
116116
try {
117117
list.add(deserializer.deserialize(this, logger));
118118
} catch (Exception e) {
119-
logger.log(SentryLevel.WARNING, "Failed to deserialize object in list.", e);
120-
try {
121-
recoverValue(startDepth, startToken);
122-
} catch (Exception recoveryException) {
123-
logger.log(
124-
SentryLevel.ERROR,
125-
"Stream unrecoverable, aborting list deserialization.",
126-
recoveryException);
119+
if (!recoverAfterValueFailure(
120+
logger,
121+
e,
122+
"Failed to deserialize object in list.",
123+
"Stream unrecoverable, aborting list deserialization.",
124+
startDepth,
125+
startToken)) {
127126
break;
128127
}
129128
}
@@ -150,14 +149,13 @@ public void nextUnknown(ILogger logger, Map<String, Object> unknown, String name
150149
try {
151150
map.put(key, deserializer.deserialize(this, logger));
152151
} catch (Exception e) {
153-
logger.log(SentryLevel.WARNING, "Failed to deserialize object in map.", e);
154-
try {
155-
recoverValue(startDepth, startToken);
156-
} catch (Exception recoveryException) {
157-
logger.log(
158-
SentryLevel.ERROR,
159-
"Stream unrecoverable, aborting map deserialization.",
160-
recoveryException);
152+
if (!recoverAfterValueFailure(
153+
logger,
154+
e,
155+
"Failed to deserialize object in map.",
156+
"Stream unrecoverable, aborting map deserialization.",
157+
startDepth,
158+
startToken)) {
161159
break;
162160
}
163161
}
@@ -190,14 +188,13 @@ public void nextUnknown(ILogger logger, Map<String, Object> unknown, String name
190188
result.put(key, list);
191189
}
192190
} catch (Exception e) {
193-
logger.log(SentryLevel.WARNING, "Failed to deserialize list in map.", e);
194-
try {
195-
recoverValue(startDepth, startToken);
196-
} catch (Exception recoveryException) {
197-
logger.log(
198-
SentryLevel.ERROR,
199-
"Stream unrecoverable, aborting map-of-lists deserialization.",
200-
recoveryException);
191+
if (!recoverAfterValueFailure(
192+
logger,
193+
e,
194+
"Failed to deserialize list in map.",
195+
"Stream unrecoverable, aborting map-of-lists deserialization.",
196+
startDepth,
197+
startToken)) {
201198
break;
202199
}
203200
}
@@ -331,6 +328,23 @@ public void skipValue() throws IOException {
331328
jsonReader.skipValue();
332329
}
333330

331+
private boolean recoverAfterValueFailure(
332+
final @NotNull ILogger logger,
333+
final @NotNull Exception error,
334+
final @NotNull String warningMessage,
335+
final @NotNull String unrecoverableMessage,
336+
final int startDepth,
337+
final @NotNull JsonToken startToken) {
338+
logger.log(SentryLevel.WARNING, warningMessage, error);
339+
try {
340+
recoverValue(startDepth, startToken);
341+
return true;
342+
} catch (Exception recoveryException) {
343+
logger.log(SentryLevel.ERROR, unrecoverableMessage, recoveryException);
344+
return false;
345+
}
346+
}
347+
334348
private void recoverValue(final int startDepth, final @NotNull JsonToken startToken)
335349
throws IOException {
336350
final boolean enteredNestedValue = depth > startDepth;

0 commit comments

Comments
 (0)