Skip to content

Commit

Permalink
Merge pull request #1201 from research-software-directory/better-ment…
Browse files Browse the repository at this point in the history
…ion-error-message

store message with metadata in the error logs when saving a mention fails
  • Loading branch information
ewan-escience authored May 17, 2024
2 parents 05baed1 + d7762e1 commit 6d9db92
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ public void save(Collection<MentionRecord> mentions) {

LOGGER.warn("Failed to save mention: {} / {} / {}", mention.doi, mention.externalId, mention.source, e);

String metadataMessage = "Failed to save mention: DOI %s, external ID %s, source %s".formatted(mention.doi, mention.externalId, mention.source);
RuntimeException exceptionWithMetadata = new RuntimeException(metadataMessage, e);
if (mention.doi == null) {
Utils.saveExceptionInDatabase("Mention scraper", "mention", null, e);
Utils.saveExceptionInDatabase("Mention scraper", "mention", null, exceptionWithMetadata);
} else {
// We will try to update the scraped_at field, so that it goes back into the queue for being scraped
// Note that this operation in itself may also fail.
Expand All @@ -118,9 +120,9 @@ public void save(Collection<MentionRecord> mentions) {
ZonedDateTime.now(),
"scraped_at");

Utils.saveExceptionInDatabase("Mention scraper", "mention", UUID.fromString(id), e);
Utils.saveExceptionInDatabase("Mention scraper", "mention", UUID.fromString(id), exceptionWithMetadata);
} else {
Utils.saveExceptionInDatabase("Mention scraper", "mention", null, e);
Utils.saveExceptionInDatabase("Mention scraper", "mention", null, exceptionWithMetadata);
}
} catch (Exception e2) {
LOGGER.warn("Failed to save exception in database", e2);
Expand Down

0 comments on commit 6d9db92

Please sign in to comment.