Xmipp  v3.23.11-Nereus
xmipp_error.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar S. Sorzano (coss@cnb.csic.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #include <iostream>
27 #include <stdlib.h>
28 #include "xmipp_error.h"
29 #include "xmipp_color.h"
30 
31 // Object Constructor
32 XmippError::XmippError(const ErrorType nerr, const String &what,
33  const String &fileArg, const long lineArg)
34  :std::runtime_error(XmippError::getMessage(nerr, what, fileArg, lineArg)), __errno(nerr)
35 {}
36 
37 String XmippError::getMessage(const ErrorType nerr, const String& what,
38  const String &fileArg, const long lineArg) {
39  String error = formatString("XMIPP_ERROR %d: %s\n ", nerr, getDefaultMessage(nerr).c_str());
40  error += what;
41  error += formatString("\n File: %s line: %ld\n", fileArg.c_str(), lineArg);
42  return error;
43 }
44 
45 String XmippError::getDefaultMessage(ErrorType e)
46 {
47  switch (e)
48  {
49  case ERR_ARG_BADCMDLINE:
50  return "Errors on command line parameters";
51  case ERR_ARG_INCORRECT:
52  return " Incorrect argument received";
53  case ERR_ARG_MISSING:
54  return " Argument missing";
55  case ERR_ARG_DEPENDENCE:
56  return "Error with some arguments dependecies";
57 
58  case ERR_PROG_NOTDEF:
59  return "Requiered function not implemented in derived class";
60  case ERR_DEBUG_TEST:
61  return " Just an error for debugging purpose";
63  return " Just for debugging: situation that can't happens";
64 
65  case ERR_DOCFILE:
66  return " Error in docfile format.";
67 
68  case ERR_GRID:
69  return " Grid general error.";
70  case ERR_GRID_SIZE:
71  return " Incorrect number of GRID volumes or shapes.";
72 
73  case ERR_IMG_NOREAD:
74  return " Image cannot be read from file.";
75  case ERR_IMG_NOWRITE:
76  return " Image cannot be written to file.";
77  case ERR_IMG_UNKNOWN:
78  return " Unknown image type.";
79 
81  return " Index out of bounds.";
82 
83  case ERR_IO:
84  return " Input/output general error.";
85  case ERR_IO_NOCLOSED:
86  return " File cannot be closed.";
87  case ERR_IO_NOPATH:
88  return " Environment PATH cannot be read.";
89  case ERR_IO_NOPERM:
90  return " Insufficient permissions to perform operation.";
91  case ERR_IO_NOREAD:
92  return " Couldn't read from file.";
93  case ERR_IO_NOTDIR:
94  return " It is not a directory.";
95  case ERR_IO_NOTEXIST:
96  return " File or directory does not exist.";
97  case ERR_IO_NOTFILE:
98  return " It is not a file";
99  case ERR_IO_NOTOPEN:
100  return "File cannot be open.";
101  case ERR_IO_NOWRITE:
102  return " Couldn't write to file.";
103  case ERR_IO_SIZE:
104  return " Incorrect file size.";
105 
106  case ERR_MATRIX:
107  return " Matrix error.";
108  case ERR_MATRIX_DIM:
109  return " Incorrect matrix dimensions.";
110  case ERR_MATRIX_EMPTY:
111  return " The matrix is empty.";
112  case ERR_MATRIX_SIZE:
113  return " Incorrect matrix size.";
114 
115  case ERR_MD:
116  return " MetaData error.";
117  case ERR_MD_BADLABEL:
118  return " Unexpected label.";
119  case ERR_MD_MISSINGLABEL:
120  return " Missing expected label.";
121  case ERR_MD_BADTYPE:
122  return " Bad label type.";
123  case ERR_MD_NOACTIVE:
124  return " No active object in MetaData.";
125  case ERR_MD_NOOBJ:
126  return " No exist requested object.";
127  case ERR_MD_SQL:
128  return " Error in SQL of MetaData operations";
129  case ERR_MD_OBJECTNUMBER:
130  return " Bad number of objects in MetaData";
131  case ERR_MD_UNDEFINED:
132  return " Undefined label.";
133  case ERR_MD_BADBLOCK:
134  return " Block not existing.";
135 
136  case ERR_MEM_BADREQUEST:
137  return " Bad amount of memory requested.";
138  case ERR_MEM_NOTENOUGH:
139  return " There is not enough memory for allocation.";
140  case ERR_MEM_NOTDEALLOC:
141  return " Memory has not been deallocated.";
142  case ERR_MEM_NULLPOINTER:
143  return " Null pointer passed as parameter.";
144 
145  case ERR_MMAP:
146  return " Global mmap error.";
147  case ERR_MMAP_NOTADDR:
148  return " Map addressing of file has failed.";
149 
150  case ERR_MULTIDIM_DIM:
151  return " Incorrect MultidimArray dimensions.";
152  case ERR_MULTIDIM_EMPTY:
153  return " MultidimArray is empty.";
154  case ERR_MULTIDIM_SIZE:
155  return " Incorrect MultidimArray size.";
156 
157  case ERR_NOT_IMPLEMENTED:
158  return " Algorithm not implemented yet.";
159 
160  case ERR_NUMERICAL:
161  return " Error related to numerical calculation.";
162 
163  case ERR_PARAM_INCORRECT:
164  return " Parameter incorrect.";
165  case ERR_PARAM_MISSING:
166  return " Parameter missing.";
167 
168  case ERR_PLANS_NOCREATE:
169  return " FFT plan cannot be created.";
170 
171  case ERR_SELFILE:
172  return " Error in selfile format";
173 
174  case ERR_THREADS_NOTINIT:
175  return " Threads cannot be initiated.";
176 
177  case ERR_TYPE_INCORRECT:
178  return " Incorrect type received";
179 
180  case ERR_UNCLASSIFIED:
181  return " Not classified error.";
182 
183  case ERR_VALUE_EMPTY:
184  return " Empty value.";
185  case ERR_VALUE_INCORRECT:
186  return " Incorrect received value.";
187  case ERR_VALUE_NOTSET:
188  return " Value has not been set.";
189 
190  default:
191  return "Unrecognized error code";
192  }
193 }
194 
195 void reportWarning(const String& what)
196 {
197  String error = formatString("=== XMIPP_WARNING ===\n%s", what.c_str());
198  std::cerr << colorString(error.c_str(), MAGENTA) << std::endl;
199 }
200 
Argument missing.
Definition: xmipp_error.h:114
Index out of bounds.
Definition: xmipp_error.h:132
Just to locate unclassified errors.
Definition: xmipp_error.h:192
Grid general error.
Definition: xmipp_error.h:125
No active object in MetaData.
Definition: xmipp_error.h:155
Errors on command line parameters.
Definition: xmipp_error.h:112
Empty value.
Definition: xmipp_error.h:194
Parameter incorrect.
Definition: xmipp_error.h:181
Case or algorithm not implemented yet.
Definition: xmipp_error.h:177
void reportWarning(const String &what)
MultidimArray is empty.
Definition: xmipp_error.h:175
Just an error for debugging purpose.
Definition: xmipp_error.h:119
Error with some arguments dependencies.
Definition: xmipp_error.h:115
Problem with matrix size.
Definition: xmipp_error.h:152
String colorString(const char *msg, int color, int attribute, int bgcolor)
Definition: xmipp_color.cpp:28
Global mmap error.
Definition: xmipp_error.h:170
No exist requested object.
Definition: xmipp_error.h:156
Just for debugging, situation that can&#39;t happens.
Definition: xmipp_error.h:120
Matrix error.
Definition: xmipp_error.h:149
Couldn&#39;t write to file.
Definition: xmipp_error.h:140
It is not a directory.
Definition: xmipp_error.h:142
Null pointer passed as parameter.
Definition: xmipp_error.h:168
There is not enough memory for allocation.
Definition: xmipp_error.h:166
The matrix is empty.
Definition: xmipp_error.h:151
Unexpected label.
Definition: xmipp_error.h:157
Unknown image type.
Definition: xmipp_error.h:130
Input/Output general error.
Definition: xmipp_error.h:134
Cannot read image from file.
Definition: xmipp_error.h:128
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
XmippError(const ErrorType nerr, const String &what, const String &fileArg, const long lineArg)
Definition: xmipp_error.cpp:32
Memory has not been deallocated.
Definition: xmipp_error.h:167
ErrorType
Definition: xmipp_error.h:109
Cannot write image to file.
Definition: xmipp_error.h:129
Bad amount of memory requested.
Definition: xmipp_error.h:165
Incorrect number of objects in Metadata.
Definition: xmipp_error.h:160
Error in docfile format.
Definition: xmipp_error.h:186
File cannot be closed.
Definition: xmipp_error.h:135
Undefined label.
Definition: xmipp_error.h:162
Error in SQL of MetaData operations.
Definition: xmipp_error.h:159
Map addressing of file has failed.
Definition: xmipp_error.h:171
It is not a file.
Definition: xmipp_error.h:141
Problem with matrix dimensions.
Definition: xmipp_error.h:150
Required function not implemented.
Definition: xmipp_error.h:117
Incorrect argument received.
Definition: xmipp_error.h:113
Error related to numerical calculation.
Definition: xmipp_error.h:179
MetaData error.
Definition: xmipp_error.h:154
Missing expected label.
Definition: xmipp_error.h:158
File or directory does not exist.
Definition: xmipp_error.h:136
Couldn&#39;t read from file.
Definition: xmipp_error.h:139
This block does not exist.
Definition: xmipp_error.h:163
Threads cannot be initiated.
Definition: xmipp_error.h:188
FFT Plan cannot be created.
Definition: xmipp_error.h:184
File cannot be open.
Definition: xmipp_error.h:137
void error(char *s)
Definition: tools.cpp:107
Bad label type.
Definition: xmipp_error.h:161
Value has not been set.
Definition: xmipp_error.h:196
Incorrect number of GRID volumes or shapes.
Definition: xmipp_error.h:126
Error in docfile format.
Definition: xmipp_error.h:122
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)
Environment PATH cannot be read.
Definition: xmipp_error.h:143
Incorrect MultidimArray dimensions.
Definition: xmipp_error.h:173
Incorrect file size.
Definition: xmipp_error.h:145
Incorrect type received.
Definition: xmipp_error.h:190
Insufficient permissions to perform operation.
Definition: xmipp_error.h:138
Incorrect value received.
Definition: xmipp_error.h:195
Parameter missing.
Definition: xmipp_error.h:182