Skip to content

Commit f81efba

Browse files
committed
Fix datafeed key json parsing
1 parent 1a03c5d commit f81efba

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

stroom-receive/stroom-receive-common/src/main/java/stroom/receive/common/DataFeedKeyDirWatcher.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import stroom.util.json.JsonUtil;
66
import stroom.util.logging.LambdaLogger;
77
import stroom.util.logging.LambdaLoggerFactory;
8+
import stroom.util.logging.LogUtil;
89
import stroom.util.shared.NullSafe;
910

10-
import com.fasterxml.jackson.databind.ObjectMapper;
11+
import com.fasterxml.jackson.databind.DeserializationFeature;
12+
import com.fasterxml.jackson.databind.ObjectReader;
1113
import jakarta.inject.Inject;
1214
import jakarta.inject.Provider;
1315
import jakarta.inject.Singleton;
@@ -102,18 +104,19 @@ private void processAllFiles() {
102104
}
103105
});
104106
LOGGER.info("Completed reading {} data feed key files in {}", counter, dirToWatch);
105-
} catch (IOException e) {
106-
LOGGER.error("Error reading contents of " + dirToWatch, e);
107+
} catch (Exception e) {
108+
LOGGER.error("Error reading contents of directory '{}': {}", dirToWatch, LogUtil.exceptionMessage(e));
107109
}
108110
}
109111

110112
private void processFile(final Path path) {
111113
if (path != null && Files.isRegularFile(path)) {
112114
LOGGER.info("Reading datafeed key file {}", path.toAbsolutePath().normalize());
113-
final ObjectMapper mapper = JsonUtil.getMapper();
115+
final ObjectReader reader = JsonUtil.getMapper().reader()
116+
.with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
114117
try (InputStream fileStream = new FileInputStream(path.toFile())) {
115118
try {
116-
final HashedDataFeedKeys hashedDataFeedKeys = mapper.readValue(fileStream,
119+
final HashedDataFeedKeys hashedDataFeedKeys = reader.readValue(fileStream,
117120
HashedDataFeedKeys.class);
118121
if (hashedDataFeedKeys != null && NullSafe.hasItems(hashedDataFeedKeys.getDataFeedKeys())) {
119122
final int addedCount = dataFeedKeyServiceProvider.get().addDataFeedKeys(hashedDataFeedKeys,
@@ -125,11 +128,12 @@ private void processFile(final Path path) {
125128
LOGGER.info("No datafeed keys found in {}", path.toAbsolutePath().normalize());
126129
}
127130
} catch (IOException e) {
128-
LOGGER.error("Error parsing file {}: {}", path, e.getMessage(), e);
129-
throw new RuntimeException(e);
131+
LOGGER.debug("Error parsing file {}: {}", path, e.getMessage(), e);
132+
LOGGER.error("Error parsing file {}: {} (enable DEBUG for stacktrace)", path, e.getMessage());
130133
}
131134
} catch (IOException e) {
132-
LOGGER.error("Error reading file {}: {}", path, e.getMessage(), e);
135+
LOGGER.debug("Error reading file {}: {}", path, e.getMessage(), e);
136+
LOGGER.error("Error reading file {}: {} (enable DEBUG for stacktrace)", path, e.getMessage());
133137
}
134138
}
135139
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
* Add data feed key json parsing errors to log. Remove stack traces from error log. Stop a bad json file breaking the dir watcher on boot.
2+
3+
4+
```sh
5+
# ONLY the top line will be included as a change entry in the CHANGELOG.
6+
# The entry should be in GitHub flavour markdown and should be written on a SINGLE
7+
# line with no hard breaks. You can have multiple change files for a single GitHub issue.
8+
# The entry should be written in the imperative mood, i.e. 'Fix nasty bug' rather than
9+
# 'Fixed nasty bug'.
10+
#
11+
# Examples of acceptable entries are:
12+
#
13+
#
14+
# * Issue **123** : Fix bug with an associated GitHub issue in this repository
15+
#
16+
# * Issue **namespace/other-repo#456** : Fix bug with an associated GitHub issue in another repository
17+
#
18+
# * Fix bug with no associated GitHub issue.
19+
```

0 commit comments

Comments
 (0)