Skip to content

Commit

Permalink
Prevent an error if history contains event of unknown type
Browse files Browse the repository at this point in the history
If a new version of Prospero introduced a new history event type, it
should still be possible to use older versions to view history
  • Loading branch information
spyrkob committed Aug 10, 2023
1 parent 542c221 commit c9a1c06
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@

public class SavedState {

public enum Type { UPDATE, INSTALL, ROLLBACK, CONFIG_CHANGE;}
public enum Type {
UPDATE, INSTALL, ROLLBACK, CONFIG_CHANGE, UNKNOWN;
public static Type fromText(String text) {
for (Type value : Type.values()) {
if (value.name().equals(text)) {
return value;
}
}
return UNKNOWN;
}
}

private String hash;
private Instant timestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public List<SavedState> getRevisions() throws MetadataException {
final String shortMessage = revCommit.getShortMessage().trim();
final int endOfTypeIndex = shortMessage.indexOf(' ');
final String type;
final String msg;
String msg;
if (endOfTypeIndex < 0) {
type = shortMessage;
msg = "";
Expand All @@ -90,9 +90,13 @@ public List<SavedState> getRevisions() throws MetadataException {
msg = shortMessage.substring(endOfTypeIndex + 1).trim();

}
final SavedState.Type recordType = SavedState.Type.fromText(type.toUpperCase(Locale.ROOT));
if (recordType == SavedState.Type.UNKNOWN) {
msg = shortMessage;
}
history.add(new SavedState(revCommit.getName().substring(0,8),
Instant.ofEpochSecond(revCommit.getCommitTime()),
SavedState.Type.valueOf(type.toUpperCase(Locale.ROOT)), msg));
recordType, msg));
}

return history;
Expand Down

0 comments on commit c9a1c06

Please sign in to comment.