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 class SnapshotException : Exception {
13     this(SnapshotError s) {
14         super(null);
15         this.errMsg = s;
16     }
17 
18     SnapshotError errMsg;
19 
20     static struct DstIsNotADir {
21         void print() {
22             logger.error("Destination must be a directory");
23         }
24     }
25 
26     static struct UnableToAcquireWorkLock {
27         string dst;
28         void print() {
29             logger.errorf("'%s' is locked by another dsnapshot instance", dst);
30         }
31     }
32 
33     static struct SyncFailed {
34         string src;
35         string dst;
36         void print() {
37             logger.errorf("Failed to sync from '%s' to '%s'", src, dst);
38         }
39     }
40 
41     static struct PreExecFailed {
42         void print() {
43             logger.error("One or more of the `pre_exec` hooks failed");
44         }
45     }
46 
47     static struct PostExecFailed {
48         void print() {
49             logger.error("One or more of the `post_exec` hooks failed");
50         }
51     }
52 }
53 
54 alias SnapshotError = SumType!(SnapshotException.DstIsNotADir, SnapshotException.UnableToAcquireWorkLock,
55         SnapshotException.SyncFailed, SnapshotException.PreExecFailed,
56         SnapshotException.PostExecFailed,);