mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-21 23:38:50 -05:00
improved exception handling
This commit is contained in:
parent
69f549c3b7
commit
a8cf61ef33
@ -20,10 +20,11 @@ public class Checksum {
|
||||
private Long checksum = null;
|
||||
private State state = State.PENDING;
|
||||
private ChecksumComputationTask computationTask = null;
|
||||
private String errorMessage = null;
|
||||
|
||||
|
||||
public static enum State {
|
||||
PENDING, INPROGRESS, READY;
|
||||
PENDING, INPROGRESS, READY, ERROR;
|
||||
}
|
||||
|
||||
|
||||
@ -67,6 +68,21 @@ public class Checksum {
|
||||
public synchronized void setChecksum(Long checksum) {
|
||||
this.checksum = checksum;
|
||||
setState(State.READY);
|
||||
|
||||
computationTask = null;
|
||||
}
|
||||
|
||||
|
||||
public synchronized void setChecksumError(Exception exception) {
|
||||
// get root cause
|
||||
Throwable cause = exception;
|
||||
|
||||
while (cause.getCause() != null)
|
||||
cause = cause.getCause();
|
||||
|
||||
errorMessage = cause.getMessage();
|
||||
setState(State.ERROR);
|
||||
|
||||
computationTask = null;
|
||||
}
|
||||
|
||||
@ -83,14 +99,15 @@ public class Checksum {
|
||||
|
||||
|
||||
public Integer getProgress() {
|
||||
switch (state) {
|
||||
case PENDING:
|
||||
return 0;
|
||||
case READY:
|
||||
return 100;
|
||||
default:
|
||||
return computationTask.getProgress();
|
||||
}
|
||||
if (state == State.INPROGRESS)
|
||||
return computationTask.getProgress();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
|
||||
@ -123,6 +140,7 @@ public class Checksum {
|
||||
setChecksum(computationTask.get());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
setChecksumError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -141,16 +159,13 @@ public class Checksum {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
switch (state) {
|
||||
case PENDING:
|
||||
return state.toString();
|
||||
case INPROGRESS:
|
||||
return state.toString();
|
||||
case READY:
|
||||
return getChecksumString();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
if (state == State.READY)
|
||||
return getChecksumString();
|
||||
|
||||
if (state == State.ERROR)
|
||||
return getErrorMessage();
|
||||
|
||||
return state.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,13 +45,15 @@ public class ChecksumRow {
|
||||
|
||||
public State getState() {
|
||||
HashSet<Long> checksums = new HashSet<Long>();
|
||||
boolean ready = true;
|
||||
|
||||
for (Checksum checksum : checksumMap.values()) {
|
||||
if (checksum.getState() == Checksum.State.READY)
|
||||
for (Checksum checksum : getChecksums()) {
|
||||
if (checksum.getState() == Checksum.State.READY) {
|
||||
checksums.add(checksum.getChecksum());
|
||||
else
|
||||
ready = false;
|
||||
} else if (checksum.getState() == Checksum.State.ERROR) {
|
||||
return State.ERROR;
|
||||
} else {
|
||||
return State.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
if (checksums.size() > 1) {
|
||||
@ -65,10 +67,6 @@ public class ChecksumRow {
|
||||
return State.WARNING;
|
||||
}
|
||||
|
||||
if (!ready) {
|
||||
return State.UNKNOWN;
|
||||
}
|
||||
|
||||
return State.OK;
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,8 @@ public class ChecksumTableCellRenderer extends TextTableCellRenderer {
|
||||
setText(checksum.getChecksumString());
|
||||
} else if (checksum.getState() == Checksum.State.PENDING) {
|
||||
setText("Pending ...");
|
||||
} else if (checksum.getState() == Checksum.State.ERROR) {
|
||||
setText(checksum.getErrorMessage());
|
||||
} else {
|
||||
return progressBarRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@ -31,10 +32,12 @@ public abstract class FileTransferablePolicy extends TransferablePolicy {
|
||||
protected List<File> getFilesFromTransferable(Transferable tr) {
|
||||
List<File> files = getFilesFromFileTransferable(tr);
|
||||
|
||||
// if there is no file transferable, look if there is a string transferable
|
||||
// if there is no file transferable, look if there is a string transferable that contains file uris
|
||||
if (files == null)
|
||||
files = getFilesFromStringTransferable(tr);
|
||||
|
||||
Collections.sort(files);
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user