1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-25 09:18:51 -05:00

* better error reporting

This commit is contained in:
Reinhard Pointner 2013-10-20 13:10:21 +00:00
parent c7e25998fb
commit d054c50c18
3 changed files with 26 additions and 34 deletions

View File

@ -1,7 +1,5 @@
package net.sourceforge.filebot.cli; package net.sourceforge.filebot.cli;
import static java.lang.System.*; import static java.lang.System.*;
import java.io.PrintStream; import java.io.PrintStream;
@ -10,58 +8,55 @@ import java.util.logging.Level;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.codehaus.groovy.runtime.StackTraceUtils;
class CLILogging extends Handler { class CLILogging extends Handler {
public static final Logger CLILogger = createCommandlineLogger("net.sourceforge.filebot.logger.cli"); public static final Logger CLILogger = createCommandlineLogger("net.sourceforge.filebot.logger.cli");
private static Logger createCommandlineLogger(String name) { private static Logger createCommandlineLogger(String name) {
Logger log = Logger.getLogger(name); Logger log = Logger.getLogger(name);
log.setLevel(Level.ALL); log.setLevel(Level.ALL);
// don't use parent handlers // don't use parent handlers
log.setUseParentHandlers(false); log.setUseParentHandlers(false);
// CLI handler // CLI handler
log.addHandler(new CLILogging()); log.addHandler(new CLILogging());
return log; return log;
} }
@Override @Override
public void publish(LogRecord record) { public void publish(LogRecord record) {
if (record.getLevel().intValue() <= getLevel().intValue()) if (record.getLevel().intValue() <= getLevel().intValue())
return; return;
// make sure all previous messages are already flushed // make sure all previous messages are already flushed
System.out.flush(); System.out.flush();
System.err.flush(); System.err.flush();
// use either System.out or System.err depending on the severity of the error // use either System.out or System.err depending on the severity of the error
PrintStream out = record.getLevel().intValue() < Level.WARNING.intValue() ? System.out : System.err; PrintStream out = record.getLevel().intValue() < Level.WARNING.intValue() ? System.out : System.err;
// print messages // print messages
out.println(record.getMessage()); out.println(record.getMessage());
if (record.getThrown() != null) { if (record.getThrown() != null) {
record.getThrown().printStackTrace(out); StackTraceUtils.deepSanitize(record.getThrown()).printStackTrace(out);
} }
// flush every message immediately // flush every message immediately
out.flush(); out.flush();
} }
@Override @Override
public void close() throws SecurityException { public void close() throws SecurityException {
} }
@Override @Override
public void flush() { public void flush() {
out.flush(); out.flush();
} }
} }

View File

@ -89,7 +89,10 @@ public class TMDbClient implements MovieIdentificationService {
} }
result.add(new Movie(title, title.equals(originalTitle) ? new String[] {} : new String[] { originalTitle }, year, -1, (int) id)); result.add(new Movie(title, title.equals(originalTitle) ? new String[] {} : new String[] { originalTitle }, year, -1, (int) id));
} catch (Exception e) { } catch (Exception e) {
Logger.getLogger(TMDbClient.class.getName()).log(Level.WARNING, String.format("Ignore movie [%s]: %s", title, e.getMessage())); // only print 'missing release date' warnings for matching movie titles
if (query.equalsIgnoreCase(title) || query.equalsIgnoreCase(originalTitle)) {
Logger.getLogger(TMDbClient.class.getName()).log(Level.WARNING, String.format("Ignore movie [%s]: %s", title, e.getMessage()));
}
} }
} }
return result; return result;

View File

@ -185,18 +185,12 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
return cachedItem; return cachedItem;
} }
try { Document dom = getXmlResource(MirrorType.XML, "/api/" + apikey + "/series/" + id + "/all/" + getLanguageCode(locale) + ".xml");
Document dom = getXmlResource(MirrorType.XML, "/api/" + apikey + "/series/" + id + "/all/" + getLanguageCode(locale) + ".xml"); String name = selectString("//SeriesName", dom);
String name = selectString("//SeriesName", dom);
TheTVDBSearchResult series = new TheTVDBSearchResult(name, id); TheTVDBSearchResult series = new TheTVDBSearchResult(name, id);
getCache().putData("lookupByID", id, locale, series); getCache().putData("lookupByID", id, locale, series);
return series; return series;
} catch (FileNotFoundException e) {
// illegal series id
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to retrieve base series record: " + e.getMessage());
return null;
}
} }
public TheTVDBSearchResult lookupByIMDbID(int imdbid, Locale locale) throws Exception { public TheTVDBSearchResult lookupByIMDbID(int imdbid, Locale locale) throws Exception {
@ -291,7 +285,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
try { try {
return resource.getDocument(); return resource.getDocument();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new FileNotFoundException("Resource not found: " + getResourceURL(mirrorType, path)); // simplify error message throw new IllegalArgumentException("Resource not found: " + getResourceURL(mirrorType, path)); // simplify error message
} }
} }