Skip to content

Commit

Permalink
Fix NPE's trying to cache profiles & when there are no blacklisted paths
Browse files Browse the repository at this point in the history
  • Loading branch information
shayaantx committed Feb 16, 2021
1 parent 7962687 commit 31f727e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/main/java/com/botdarr/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,13 @@ public static ChatClientType getChatClientType() {

public static List<String> getExistingItemBlacklistPaths() {
String paths = getProperty(Constants.EXISTING_ITEMS_PATHS_BLACKLIST);
if (paths != null && paths.contains(",")) {
return Arrays.asList(paths.split(","));
if (paths != null) {
if (paths.contains(",")) {
return Arrays.asList(paths.split(","));
}
return new ArrayList<String>() {{add(paths);}};
}
return new ArrayList<String>() {{add(paths);}};
return new ArrayList<>();
}

public static final class Constants {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/botdarr/api/AddStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ChatClientResponse addWithSearchId(String searchText, String id) {
}
}
return chatClientResponseBuilder.createErrorMessage("Could not find " + contentDisplayName + " with search text=" + searchText + " and id=" + id);
} catch (Exception e) {
} catch (Throwable e) {
LOGGER.error("Error trying to add " + contentDisplayName, e);
return chatClientResponseBuilder.createErrorMessage("Error adding content, e=" + e.getMessage());
}
Expand Down Expand Up @@ -80,7 +80,7 @@ public List<ChatClientResponse> addWithSearchTitle(String searchText) {
return Arrays.asList(chatClientResponseBuilder.createInfoMessage("No new " + contentDisplayName + "s found, check existing " + contentDisplayName + "s"));
}
return restOfItems;
} catch (Exception e) {
} catch (Throwable e) {
LOGGER.error("Error trying to add " + contentDisplayName, e);
return Arrays.asList(chatClientResponseBuilder.createErrorMessage("Error trying to add " + contentDisplayName + ", for search text=" + searchText + ", e=" + e.getMessage()));
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/botdarr/api/CacheProfileStrategy.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.botdarr.api;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -11,10 +14,15 @@ public abstract class CacheProfileStrategy<Z extends KeyBased<X>, X> {
public void cacheData() {
List<X> profilesAddUpdated = new ArrayList<>();
List<Z> profiles = getProfiles();
if (profiles == null) {
LOGGER.warn("Did not find any profiles available for caching, class=" + this.getClass().toString());
return;
}
for (Z profile : profiles) {
addProfile(profile);
profilesAddUpdated.add(profile.getKey());
}
deleteFromCache(profilesAddUpdated);
}
private static final Logger LOGGER = LogManager.getLogger();
}
2 changes: 1 addition & 1 deletion src/main/java/com/botdarr/commands/CommandProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public <T extends ChatClientResponse, Z extends Api> CommandResponse processMess
return new CommandResponse(chatClientResponseBuilder.createErrorMessage("Invalid command - type " + commandPrefix + "help for command usage"));
}

} catch (Exception e) {
} catch (Throwable e) {
LOGGER.error("Error trying to execute command " + strippedMessage, e);
return new CommandResponse(chatClientResponseBuilder.createErrorMessage("Error trying to parse command " + strippedMessage + ", error=" + e.getMessage()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public List<ChatClientResponse> onFailure(int statusCode, String reason) {

@Override
public List<ChatClientResponse> onException(Exception e) {
return Arrays.asList(chatClientResponseBuilder.createErrorMessage("Requested failed with exception, e=" + e.getMessage()));
return Arrays.asList(chatClientResponseBuilder.createErrorMessage("Requested failed with exception, e=" + e.getMessage() + ",class=" + e.getClass()));
}
private ChatClientResponseBuilder<? extends ChatClientResponse> chatClientResponseBuilder;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.4
5.1.5

0 comments on commit 31f727e

Please sign in to comment.