-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patherror.h
134 lines (115 loc) · 3.89 KB
/
error.h
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
/*
Pheniqs : PHilology ENcoder wIth Quality Statistics
Copyright (C) 2018 Lior Galanti
NYU Center for Genetics and System Biology
Author: Lior Galanti <lior.galanti@nyu.edu>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PHENIQS_ERROR_H
#define PHENIQS_ERROR_H
/* TODO: errno
https://en.cppreference.com/w/cpp/header/cerrno
htslib returns errno error codees, need to go over api calls and propegate correct errors */
#include "include.h"
/* Those are possible return values when pheniqs terminates */
enum class ErrorCode : int8_t {
OK = 0,
UNKNOWN_ERROR = 1,
INTERNAL_ERROR = 2,
CONFIGURATION_ERROR = 3,
OUT_OF_MEMORY_ERROR = 4,
COMMAND_LINE_ERROR = 5,
IO_ERROR = 6,
SEQUENCE_ERROR = 7,
OVERFLOW_ERROR = 8,
CORRUPT_AUXILIARY_ERROR = 9,
JSON_VALIDATION_ERROR = 10,
};
class Error : public exception {
protected:
Error(const string& name, const ErrorCode& code) :
name(name),
code(code) {
};
Error(const string& name, const ErrorCode& code, const string& message) :
name(name),
code(code),
message(message) {
};
public:
const string name;
const ErrorCode code;
list< string > stack;
string message;
void push(const string& where) {
stack.emplace_back(where);
};
const char* what() const noexcept override {
return name.c_str();
};
virtual ostream& describe(ostream& o) const {
o << name;
o << " : ";
o << message;
o << endl;
return o;
};
};
class OutOfMemoryError : public Error {
public:
OutOfMemoryError() :
Error("Out of memory error", ErrorCode::OUT_OF_MEMORY_ERROR) {
};
};
class InternalError : public Error {
public:
InternalError(const string& message) :
Error("Internal error", ErrorCode::INTERNAL_ERROR, message) {
};
};
class ConfigurationError : public Error {
public:
ConfigurationError(const string& message) :
Error("Configuration error", ErrorCode::CONFIGURATION_ERROR, message) {
};
};
class CommandLineError : public Error {
public:
CommandLineError(const string& message) :
Error("Command line error", ErrorCode::COMMAND_LINE_ERROR, message) {
};
};
class IOError : public Error {
public:
IOError(const string& message) :
Error("IO error", ErrorCode::IO_ERROR, message) {
};
};
class SequenceError : public Error {
public:
SequenceError(const string& message) :
Error("Sequence error", ErrorCode::SEQUENCE_ERROR, message) {
};
};
class OverflowError : public Error {
public:
OverflowError(const string& message) :
Error("Overflow error", ErrorCode::OVERFLOW_ERROR, message) {
};
};
class CorruptAuxiliaryError : public Error {
public:
CorruptAuxiliaryError(const string& message) :
Error("Corrupt auxiliary error", ErrorCode::CORRUPT_AUXILIARY_ERROR, message) {
};
};
#endif /* PHENIQS_ERROR_H */