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

View file

@ -18,21 +18,16 @@ private immutable {
class OneDriveException: Exception
{
// https://docs.microsoft.com/en-us/onedrive/developer/rest-api/concepts/errors
int httpStatusCode;
// https://dev.onedrive.com/misc/errors.htm
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__)
{
this.httpStatusCode = httpStatusCode;
this.error = error;
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__)
@ -40,7 +35,7 @@ class OneDriveException: Exception
this.httpStatusCode = httpStatusCode;
this.error = error;
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;
return data.length;
};
try {
http.perform();
} catch (CurlException e) {
throw new OneDriveException(e.msg, e);
}
http.perform();
JSONValue json;
try {
json = content.parseJSON();

View file

@ -99,14 +99,9 @@ private bool testFileHash(string path, const ref Item item)
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);
}
@nogc @safe pure nothrow this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__)
{
super(msg, file, line, next);
super(msg, file, line);
}
}
@ -419,21 +414,13 @@ final class SyncEngine
// scan the given directory for differences
public void scanForDifferences(string path)
{
try {
log.vlog("Uploading differences ...");
Item item;
if (itemdb.selectByPath(path, 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 differences ...");
Item item;
if (itemdb.selectByPath(path, item)) {
uploadDifferences(item);
}
log.vlog("Uploading new items ...");
uploadNewItems(path);
}
private void uploadDifferences(Item item)