-
Notifications
You must be signed in to change notification settings - Fork 0
/
version_exceptions.hpp
155 lines (114 loc) · 4.07 KB
/
version_exceptions.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* ****************************************************************************
* File: Control version storage exceptions.
* Author: Devid Dokash.
* Date: 15/05/2022.
* ***************************************************************************/
#pragma once
#include <exception>
#include <string>
struct version_not_installed : public std::exception {
version_not_installed() {}
const char * what () const throw () {
return "version: error: version was not installed yet, run version init";
}
};
struct file_not_found : public std::exception {
std::string file;
std::string msg;
file_not_found(std::string file) : file(file) {
msg = ("version: error: file \'" + file + "\' was not found.");
}
const char * what () const throw () {
return msg.c_str();
}
};
struct file_not_followed : public std::exception {
std::string file;
std::string msg;
file_not_followed(std::string file) : file(file) {
msg = ("version: error: file \'" + file + "\' not followed.");
}
const char * what () const throw () {
return msg.c_str();
}
};
struct file_already_followed : public std::exception {
std::string file;
std::string msg;
file_already_followed(std::string file) : file(file) {
msg = ("version: warning: file \'" + file + "\' was already followed.");
}
const char * what () const throw () {
return msg.c_str();
}
};
struct version_not_found : public std::exception {
std::string name;
int n;
std::string msg;
version_not_found(std::string name) : name(name) {
msg = ("version: error: version under name \'" + name + "\' not found.");
}
version_not_found(int n) : n(n) {
msg = ("version: error: no version " + std::to_string(n) + " available");
}
const char * what () const throw () {
return msg.c_str();
}
};
struct unknown_option : public std::exception {
std::string option;
std::string msg;
unknown_option(std::string option) : option(option) {
msg = ("version: error: unknown option \'" + option + "\'.");
}
const char * what () const throw () {
return msg.c_str();
}
};
struct bad_option_usage : public std::exception {
std::string option;
std::string msg;
bad_option_usage(std::string option) : option(option) {
msg = ("version: error: incorrect option usage ");
if(!option.compare("add")) msg += "--> version add <file>";
else if(!option.compare("erase")) msg += "--> version erase";
else if(!option.compare("help")) msg += "--> version help";
else if(!option.compare("init")) msg += "--> version init";
else if(!option.compare("log")) msg += "--> version log [<file>]";
else if(!option.compare("remove")) msg += "--> version remove <file>";
else if(!option.compare("restore")) msg += "--> version restore <file> --version <n>";
else if(!option.compare("see")) msg += "--> version see <file>";
else if(!option.compare("update")) msg += "--> version update <file> [--name <name>][--comm \"<desc>\"]";
}
const char * what () const throw () {
return msg.c_str();
}
};
struct version_name_not_valid : public std::exception {
std::string name;
std::string msg;
version_name_not_valid(std::string name) : name(name) {
msg = "version: error: given name \'" + name + "\' contains invalid " +
"symbols. Valid symbols: alphanumeric, \'_\'";
}
const char * what () const throw () {
return msg.c_str();
}
};
struct already_named_version : public std::exception {
std::string msg;
already_named_version(std::string file, std::string name) {
msg = "version: error: there is already a version named \'" + name
+ "\' in file \'" + file + "\'.";
}
const char * what () const throw () {
return msg.c_str();
}
};
struct too_long_description : public std::exception {
too_long_description() {}
const char * what () const throw () {
return "version: error: descriptions have a max length of 150 symbols.";
}
};