1 /** 2 Copyright: Copyright (c) 2019, Joakim Brännström. All rights reserved. 3 License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) 4 Author: Joakim Brännström (joakim.brannstrom@gmx.com) 5 */ 6 module dsnapshot.exception; 7 8 import logger = std.experimental.logger; 9 10 import sumtype; 11 12 @safe: 13 14 class SnapshotException : Exception { 15 this(SnapshotError s) { 16 super(null); 17 this.errMsg = s; 18 } 19 20 SnapshotError errMsg; 21 22 static struct DstIsNotADir { 23 void print() { 24 logger.error("Destination must be a directory"); 25 } 26 } 27 28 static struct UnableToAcquireWorkLock { 29 string dst; 30 void print() { 31 logger.errorf("'%s' is locked by another dsnapshot instance", dst); 32 } 33 } 34 35 static struct SyncFailed { 36 string src; 37 string dst; 38 void print() { 39 logger.errorf("Failed to sync '%s' to '%s'", src, dst); 40 } 41 } 42 43 static struct RestoreFailed { 44 string src; 45 string dst; 46 void print() { 47 logger.errorf("Failed to restore '%s' to '%s'", src, dst); 48 } 49 } 50 51 static struct PreExecFailed { 52 void print() { 53 logger.error("One or more of the `pre_exec` hooks failed"); 54 } 55 } 56 57 static struct PostExecFailed { 58 void print() { 59 logger.error("One or more of the `post_exec` hooks failed"); 60 } 61 } 62 } 63 64 alias SnapshotError = SumType!(SnapshotException.DstIsNotADir, 65 SnapshotException.UnableToAcquireWorkLock, SnapshotException.SyncFailed, 66 SnapshotException.PreExecFailed, SnapshotException.PostExecFailed, 67 SnapshotException.RestoreFailed);