removed exception chaining

This commit is contained in:
skilion 2017-12-28 15:03:15 +01:00
parent 789ec85e0c
commit 35ce743b39
3 changed files with 17 additions and 39 deletions

View file

@ -120,7 +120,7 @@ int main(string[] args)
log.vlog("[M] Directory created: ", path); log.vlog("[M] Directory created: ", path);
try { try {
sync.scanForDifferences(path); sync.scanForDifferences(path);
} catch(SyncException e) { } catch(Exception e) {
log.log(e.msg); log.log(e.msg);
} }
}; };
@ -128,7 +128,7 @@ int main(string[] args)
log.vlog("[M] File changed: ", path); log.vlog("[M] File changed: ", path);
try { try {
sync.scanForDifferences(path); sync.scanForDifferences(path);
} catch(SyncException e) { } catch(Exception e) {
log.log(e.msg); log.log(e.msg);
} }
}; };
@ -136,7 +136,7 @@ int main(string[] args)
log.vlog("[M] Item deleted: ", path); log.vlog("[M] Item deleted: ", path);
try { try {
sync.deleteByPath(path); sync.deleteByPath(path);
} catch(SyncException e) { } catch(Exception e) {
log.log(e.msg); log.log(e.msg);
} }
}; };
@ -144,7 +144,7 @@ int main(string[] args)
log.vlog("[M] Item moved: ", from, " -> ", to); log.vlog("[M] Item moved: ", from, " -> ", to);
try { try {
sync.uploadMoveItem(from, to); sync.uploadMoveItem(from, to);
} catch(SyncException e) { } catch(Exception e) {
log.log(e.msg); log.log(e.msg);
} }
}; };
@ -184,7 +184,7 @@ void performSync(SyncEngine sync)
sync.applyDifferences(); sync.applyDifferences();
sync.scanForDifferences("."); sync.scanForDifferences(".");
count = -1; count = -1;
} catch (SyncException e) { } catch (Exception e) {
if (++count == 3) throw e; if (++count == 3) throw e;
else log.log(e.msg); else log.log(e.msg);
} }

View file

@ -18,21 +18,16 @@ private immutable {
class OneDriveException: Exception class OneDriveException: Exception
{ {
// https://docs.microsoft.com/en-us/onedrive/developer/rest-api/concepts/errors
int httpStatusCode; int httpStatusCode;
// https://dev.onedrive.com/misc/errors.htm
JSONValue error; JSONValue error;
@nogc @safe pure nothrow this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__)
{
super(msg, file, line, next);
}
@safe pure this(int httpStatusCode, string reason, string file = __FILE__, size_t line = __LINE__) @safe pure this(int httpStatusCode, string reason, string file = __FILE__, size_t line = __LINE__)
{ {
this.httpStatusCode = httpStatusCode; this.httpStatusCode = httpStatusCode;
this.error = error; this.error = error;
string msg = format("HTTP request returned status code %d (%s)", httpStatusCode, reason); string msg = format("HTTP request returned status code %d (%s)", httpStatusCode, reason);
super(msg, file, line, next); super(msg, file, line);
} }
this(int httpStatusCode, string reason, ref const JSONValue error, string file = __FILE__, size_t line = __LINE__) this(int httpStatusCode, string reason, ref const JSONValue error, string file = __FILE__, size_t line = __LINE__)
@ -40,7 +35,7 @@ class OneDriveException: Exception
this.httpStatusCode = httpStatusCode; this.httpStatusCode = httpStatusCode;
this.error = error; this.error = error;
string msg = format("HTTP request returned status code %d (%s)\n%s", httpStatusCode, reason, toJSON(error, true)); string msg = format("HTTP request returned status code %d (%s)\n%s", httpStatusCode, reason, toJSON(error, true));
super(msg, file, line, next); super(msg, file, line);
} }
} }
@ -380,11 +375,7 @@ final class OneDriveApi
content ~= data; content ~= data;
return data.length; return data.length;
}; };
try { http.perform();
http.perform();
} catch (CurlException e) {
throw new OneDriveException(e.msg, e);
}
JSONValue json; JSONValue json;
try { try {
json = content.parseJSON(); json = content.parseJSON();

View file

@ -99,14 +99,9 @@ private bool testFileHash(string path, const ref Item item)
class SyncException: Exception class SyncException: Exception
{ {
@nogc @safe pure nothrow this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) @nogc @safe pure nothrow this(string msg, string file = __FILE__, size_t line = __LINE__)
{ {
super(msg, file, line, next); super(msg, file, line);
}
@nogc @safe pure nothrow this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__)
{
super(msg, file, line, next);
} }
} }
@ -419,21 +414,13 @@ final class SyncEngine
// scan the given directory for differences // scan the given directory for differences
public void scanForDifferences(string path) public void scanForDifferences(string path)
{ {
try { log.vlog("Uploading differences ...");
log.vlog("Uploading differences ..."); Item item;
Item item; if (itemdb.selectByPath(path, item)) {
if (itemdb.selectByPath(path, item)) { uploadDifferences(item);
uploadDifferences(item);
}
log.vlog("Uploading new items ...");
uploadNewItems(path);
} catch (ErrnoException e) {
throw new SyncException(e.msg, e);
} catch (FileException e) {
throw new SyncException(e.msg, e);
} catch (OneDriveException e) {
throw new SyncException(e.msg, e);
} }
log.vlog("Uploading new items ...");
uploadNewItems(path);
} }
private void uploadDifferences(Item item) private void uploadDifferences(Item item)