1 /**
2  * This module defines error code and functions related to exceptions and general error handling.
3  */
4 module harud.error;
5 
6 /* error-code */
7 enum uint ARRAY_COUNT_ERR = 0x1001;
8 enum uint ARRAY_ITEM_NOT_FOUND = 0x1002;
9 enum uint ARRAY_ITEM_UNEXPECTED_TYPE = 0x1003;
10 enum uint BINARY_LENGTH_ERR = 0x1004;
11 enum uint CANNOT_GET_PALLET = 0x1005;
12 enum uint DICT_COUNT_ERR = 0x1007;
13 enum uint DICT_ITEM_NOT_FOUND = 0x1008;
14 enum uint DICT_ITEM_UNEXPECTED_TYPE = 0x1009;
15 enum uint DICT_STREAM_LENGTH_NOT_FOUND = 0x100A;
16 enum uint DOC_ENCRYPTDICT_NOT_FOUND = 0x100B;
17 enum uint DOC_INVALID_OBJECT = 0x100C;
18 /* = 0x100D */
19 enum uint DUPLICATE_REGISTRATION = 0x100E;
20 enum uint EXCEED_JWW_CODE_NUM_LIMIT = 0x100F;
21 /* = 0x1010 */
22 enum uint ENCRYPT_INVALID_PASSWORD = 0x1011;
23 /* = 0x1012 */
24 enum uint ERR_UNKNOWN_CLASS = 0x1013;
25 enum uint EXCEED_GSTATE_LIMIT = 0x1014;
26 enum uint FAILD_TO_ALLOC_MEM = 0x1015;
27 enum uint FILE_IO_ERROR = 0x1016;
28 enum uint FILE_OPEN_ERROR = 0x1017;
29 /* = 0x1018 */
30 enum uint FONT_EXISTS = 0x1019;
31 enum uint FONT_INVALID_WIDTHS_TABLE = 0x101A;
32 enum uint INVALID_AFM_HEADER = 0x101B;
33 enum uint INVALID_ANNOTATION = 0x101C;
34 /* = 0x101D */
35 enum uint INVALID_BIT_PER_COMPONENT = 0x101E;
36 enum uint INVALID_CHAR_MATRICS_DATA = 0x101F;
37 enum uint INVALID_COLOR_SPACE = 0x1020;
38 enum uint INVALID_COMPRESSION_MODE = 0x1021;
39 enum uint INVALID_DATE_TIME = 0x1022;
40 enum uint INVALID_DESTINATION = 0x1023;
41 /* = 0x1024 */
42 enum uint INVALID_DOCUMENT = 0x1025;
43 enum uint INVALID_DOCUMENT_STATE = 0x1026;
44 enum uint INVALID_ENCODER = 0x1027;
45 enum uint INVALID_ENCODER_TYPE = 0x1028;
46 /* = 0x1029 */
47 /* = 0x102A */
48 enum uint INVALID_ENCODING_NAME = 0x102B;
49 enum uint INVALID_ENCRYPT_KEY_LEN = 0x102C;
50 enum uint INVALID_FONTDEF_DATA = 0x102D;
51 enum uint INVALID_FONTDEF_TYPE = 0x102E;
52 enum uint INVALID_FONT_NAME = 0x102F;
53 enum uint INVALID_IMAGE = 0x1030;
54 enum uint INVALID_JPEG_DATA = 0x1031;
55 enum uint INVALID_N_DATA = 0x1032;
56 enum uint INVALID_OBJECT = 0x1033;
57 enum uint INVALID_OBJ_ID = 0x1034;
58 enum uint INVALID_OPERATION = 0x1035;
59 enum uint INVALID_OUTLINE = 0x1036;
60 enum uint INVALID_PAGE = 0x1037;
61 enum uint INVALID_PAGES = 0x1038;
62 enum uint INVALID_PARAMETER = 0x1039;
63 /* = 0x103A */
64 enum uint INVALID_PNG_IMAGE = 0x103B;
65 enum uint INVALID_STREAM = 0x103C;
66 enum uint MISSING_FILE_NAME_ENTRY = 0x103D;
67 /* = 0x103E */
68 enum uint INVALID_TTC_FILE = 0x103F;
69 enum uint INVALID_TTC_INDEX = 0x1040;
70 enum uint INVALID_WX_DATA = 0x1041;
71 enum uint ITEM_NOT_FOUND = 0x1042;
72 enum uint LIBPNG_ERROR = 0x1043;
73 enum uint NAME_INVALID_VALUE = 0x1044;
74 enum uint NAME_OUT_OF_RANGE = 0x1045;
75 /* = 0x1046 */
76 /* = 0x1047 */
77 enum uint PAGE_INVALID_PARAM_COUNT = 0x1048;
78 enum uint PAGES_MISSING_KIDS_ENTRY = 0x1049;
79 enum uint PAGE_CANNOT_FIND_OBJECT = 0x104A;
80 enum uint PAGE_CANNOT_GET_ROOT_PAGES = 0x104B;
81 enum uint PAGE_CANNOT_RESTORE_GSTATE = 0x104C;
82 enum uint PAGE_CANNOT_SET_PARENT = 0x104D;
83 enum uint PAGE_FONT_NOT_FOUND = 0x104E;
84 enum uint PAGE_INVALID_FONT = 0x104F;
85 enum uint PAGE_INVALID_FONT_SIZE = 0x1050;
86 enum uint PAGE_INVALID_GMODE = 0x1051;
87 enum uint PAGE_INVALID_INDEX = 0x1052;
88 enum uint PAGE_INVALID_ROTATE_VALUE = 0x1053;
89 enum uint PAGE_INVALID_SIZE = 0x1054;
90 enum uint PAGE_INVALID_XOBJECT = 0x1055;
91 enum uint PAGE_OUT_OF_RANGE = 0x1056;
92 enum uint REAL_OUT_OF_RANGE = 0x1057;
93 enum uint STREAM_EOF = 0x1058;
94 enum uint STREAM_READLN_CONTINUE = 0x1059;
95 /* = 0x105A */
96 enum uint STRING_OUT_OF_RANGE = 0x105B;
97 enum uint THIS_FUNC_WAS_SKIPPED = 0x105C;
98 enum uint TTF_CANNOT_EMBEDDING_FONT = 0x105D;
99 enum uint TTF_INVALID_CMAP = 0x105E;
100 enum uint TTF_INVALID_FOMAT = 0x105F;
101 enum uint TTF_MISSING_TABLE = 0x1060;
102 enum uint UNSUPPORTED_FONT_TYPE = 0x1061;
103 enum uint UNSUPPORTED_FUNC = 0x1062;
104 enum uint UNSUPPORTED_JPEG_FORMAT = 0x1063;
105 enum uint UNSUPPORTED_TYPE1_FONT = 0x1064;
106 enum uint XREF_COUNT_ERR = 0x1065;
107 enum uint ZLIB_ERROR = 0x1066;
108 enum uint INVALID_PAGE_INDEX = 0x1067;
109 enum uint INVALID_URI = 0x1068;
110 enum uint PAGE_LAYOUT_OUT_OF_RANGE = 0x1069;
111 enum uint PAGE_MODE_OUT_OF_RANGE = 0x1070;
112 enum uint PAGE_NUM_STYLE_OUT_OF_RANGE = 0x1071;
113 enum uint ANNOT_INVALID_ICON = 0x1072;
114 enum uint ANNOT_INVALID_BORDER_STYLE = 0x1073;
115 enum uint PAGE_INVALID_DIRECTION = 0x1074;
116 enum uint INVALID_FONT = 0x1075;
117 enum uint PAGE_INSUFFICIENT_SPACE = 0x1076;
118 enum uint PAGE_INVALID_DISPLAY_TIME = 0x1077;
119 enum uint PAGE_INVALID_TRANSITION_TIME = 0x1078;
120 enum uint INVALID_PAGE_SLIDESHOW_TYPE = 0x1079;
121 enum uint EXT_GSTATE_OUT_OF_RANGE = 0x1080;
122 enum uint INVALID_EXT_GSTATE = 0x1081;
123 enum uint EXT_GSTATE_READ_ONLY = 0x1082;
124 enum uint INVALID_U3D_DATA = 0x1083;
125 enum uint NAME_CANNOT_GET_NAMES = 0x1084;
126 enum uint INVALID_ICC_COMPONENT_NUM = 0x1085;
127 
128 /**
129  * Returns a error description from error code
130  *
131  * Params:  errorNo = error number
132  *
133  * Returns: Error description value
134  */
135 string getErrorDescription(uint errorNo) {
136    switch (errorNo) {
137       case ARRAY_COUNT_ERR:
138          return "Array count err";
139       case ARRAY_ITEM_NOT_FOUND:
140          return "Array item not found";
141       case ARRAY_ITEM_UNEXPECTED_TYPE:
142          return "Array item unexpected type";
143       case BINARY_LENGTH_ERR:
144          return "Binary length error";
145       case CANNOT_GET_PALLET:
146          return "Cannot get pallet";
147       case DICT_COUNT_ERR:
148          return "Dict count err";
149       case DICT_ITEM_NOT_FOUND:
150          return "Dict item not found";
151       case DICT_ITEM_UNEXPECTED_TYPE:
152          return "Dict item unexpected type";
153       case DICT_STREAM_LENGTH_NOT_FOUND:
154          return "Dict stream length not found";
155       case DOC_ENCRYPTDICT_NOT_FOUND:
156          return "Doc encryptdict not found";
157       case DOC_INVALID_OBJECT:
158          return "Doc invalid object";
159       case DUPLICATE_REGISTRATION:
160          return "Duplicate registration";
161       case EXCEED_JWW_CODE_NUM_LIMIT:
162          return "Exceed JWW code num limit";
163       case ENCRYPT_INVALID_PASSWORD:
164          return "Encrypt invalid password";
165       case ERR_UNKNOWN_CLASS:
166          return "Err unknown class";
167       case EXCEED_GSTATE_LIMIT:
168          return "Exceed gstate limit";
169       case FAILD_TO_ALLOC_MEM:
170          return "Faild to alloc mem";
171       case FILE_IO_ERROR:
172          return "File IO error";
173       case FILE_OPEN_ERROR:
174          return "File open error";
175       case FONT_EXISTS:
176          return "Font exists";
177       case FONT_INVALID_WIDTHS_TABLE:
178          return "Font invalid widths table";
179       case INVALID_AFM_HEADER:
180          return "Invalid afm header";
181       case INVALID_ANNOTATION:
182          return "Invalid annotation";
183       case INVALID_BIT_PER_COMPONENT:
184          return "Invalid bit per component";
185       case INVALID_CHAR_MATRICS_DATA:
186          return "Invalid char matrics data";
187       case INVALID_COLOR_SPACE:
188          return "Invalid color space";
189       case INVALID_COMPRESSION_MODE:
190          return "Invalid compression mode";
191       case INVALID_DATE_TIME:
192          return "Invalid date time";
193       case INVALID_DESTINATION:
194          return "Invalid destination";
195       case INVALID_DOCUMENT:
196          return "Invalid document";
197       case INVALID_DOCUMENT_STATE:
198          return "Invalid document state";
199       case INVALID_ENCODER:
200          return "Invalid encoder";
201       case INVALID_ENCODER_TYPE:
202          return "Invalid encoder type";
203       case INVALID_ENCODING_NAME:
204          return "Invalid encoding name";
205       case INVALID_ENCRYPT_KEY_LEN:
206          return "Invalid encrypt key len";
207       case INVALID_FONTDEF_DATA:
208          return "Invalid fontdef data";
209       case INVALID_FONTDEF_TYPE:
210          return "Invalid fontdef type";
211       case INVALID_FONT_NAME:
212          return "Invalid font name";
213       case INVALID_IMAGE:
214          return "Invalid image";
215       case INVALID_JPEG_DATA:
216          return "Invalid JPEG data";
217       case INVALID_N_DATA:
218          return "Invalid n data";
219       case INVALID_OBJECT:
220          return "Invalid object";
221       case INVALID_OBJ_ID:
222          return "Invalid object id";
223       case INVALID_OPERATION:
224          return "Invalid operation";
225       case INVALID_OUTLINE:
226          return "Invalid outline";
227       case INVALID_PAGE:
228          return "Invalid page";
229       case INVALID_PAGES:
230          return "Invalid pages";
231       case INVALID_PARAMETER:
232          return "Invalid parameter";
233       case INVALID_PNG_IMAGE:
234          return "Invalid PNG image";
235       case INVALID_STREAM:
236          return "Invalid stream";
237       case MISSING_FILE_NAME_ENTRY:
238          return "Missing file name entry";
239       case INVALID_TTC_FILE:
240          return "Invalid TTC file";
241       case INVALID_TTC_INDEX:
242          return "Invalid TTC index";
243       case INVALID_WX_DATA:
244          return "Invalid wx data";
245       case ITEM_NOT_FOUND:
246          return "Item not found";
247       case LIBPNG_ERROR:
248          return "Libpng error";
249       case NAME_INVALID_VALUE:
250          return "Name invalid value";
251       case NAME_OUT_OF_RANGE:
252          return "Name out of range";
253       case PAGE_INVALID_PARAM_COUNT:
254          return "Page invalid param count";
255       case PAGES_MISSING_KIDS_ENTRY:
256          return "Pages missing kids entry";
257       case PAGE_CANNOT_FIND_OBJECT:
258          return "Page cannot find object";
259       case PAGE_CANNOT_GET_ROOT_PAGES:
260          return "Page cannot get root pages";
261       case PAGE_CANNOT_RESTORE_GSTATE:
262          return "Page cannot restore gstate";
263       case PAGE_CANNOT_SET_PARENT:
264          return "Page cannot set parent";
265       case PAGE_FONT_NOT_FOUND:
266          return "Page font not found";
267       case PAGE_INVALID_FONT:
268          return "Page invalid font";
269       case PAGE_INVALID_FONT_SIZE:
270          return "Page invalid font size";
271       case PAGE_INVALID_GMODE:
272          return "Page invalid gmode";
273       case PAGE_INVALID_INDEX:
274          return "Page invalid index";
275       case PAGE_INVALID_ROTATE_VALUE:
276          return "Page invalid rotate value";
277       case PAGE_INVALID_SIZE:
278          return "Page invalid size";
279       case PAGE_INVALID_XOBJECT:
280          return "Page invalid xobject";
281       case PAGE_OUT_OF_RANGE:
282          return "Page out of range";
283       case REAL_OUT_OF_RANGE:
284          return "Real out of range";
285       case STREAM_EOF:
286          return "Stream EOF";
287       case STREAM_READLN_CONTINUE:
288          return "Stream readln continue";
289       case STRING_OUT_OF_RANGE:
290          return "String out of range";
291       case THIS_FUNC_WAS_SKIPPED:
292          return "This function was skipped";
293       case TTF_CANNOT_EMBEDDING_FONT:
294          return "TTF cannot embedding font";
295       case TTF_INVALID_CMAP:
296          return "TTF invalid cmap";
297       case TTF_INVALID_FOMAT:
298          return "TTF invalid fomat";
299       case TTF_MISSING_TABLE:
300          return "TTF missing table";
301       case UNSUPPORTED_FONT_TYPE:
302          return "Unsupported font type";
303       case UNSUPPORTED_FUNC:
304          return "Unsupported func";
305       case UNSUPPORTED_JPEG_FORMAT:
306          return "Unsupported jpeg format";
307       case UNSUPPORTED_TYPE1_FONT:
308          return "Unsupported type1_font";
309       case XREF_COUNT_ERR:
310          return "Xref count err";
311       case ZLIB_ERROR:
312          return "ZLIB error";
313       case INVALID_PAGE_INDEX:
314          return "Invalid page index";
315       case INVALID_URI:
316          return "Invalid URI";
317       case PAGE_LAYOUT_OUT_OF_RANGE:
318          return "Page layout out of range";
319       case PAGE_MODE_OUT_OF_RANGE:
320          return "Page mode out of range";
321       case PAGE_NUM_STYLE_OUT_OF_RANGE:
322          return "Page num style out of range";
323       case ANNOT_INVALID_ICON:
324          return "Annot invalid icon";
325       case ANNOT_INVALID_BORDER_STYLE:
326          return "Annot invalid border style";
327       case PAGE_INVALID_DIRECTION:
328          return "Page invalid direction";
329       case INVALID_FONT:
330          return "Invalid font";
331       case PAGE_INSUFFICIENT_SPACE:
332          return "Page insufficient space";
333       case PAGE_INVALID_DISPLAY_TIME:
334          return "Page invalid display time";
335       case PAGE_INVALID_TRANSITION_TIME:
336          return "Page invalid transition time";
337       case INVALID_PAGE_SLIDESHOW_TYPE:
338          return "Invalid page slideshow type";
339       case EXT_GSTATE_OUT_OF_RANGE:
340          return "Ext gstate out of range";
341       case INVALID_EXT_GSTATE:
342          return "Invalid ext gstate";
343       case EXT_GSTATE_READ_ONLY:
344          return "Ext gstate read only";
345       case INVALID_U3D_DATA:
346          return "Invalid U3D data";
347       case NAME_CANNOT_GET_NAMES:
348          return "Name cannot get names";
349       case INVALID_ICC_COMPONENT_NUM:
350          return "Invalid ICc component num";
351 
352       default:
353          return "Unknown";
354    }
355 }
356 
357 /**
358  * Thrown if errors that set errno occur.
359  */
360 class HarudException : Exception {
361    this(uint errCode) {
362       this.errCode = errCode;
363       super(getErrorDescription(errCode));
364    }
365 
366    this(string msg, string file = __FILE__, int line = __LINE__) {
367       super(msg, file, line);
368    }
369 
370    private uint _errCode;
371    @property uint errCode() const pure nothrow {
372       return _errCode;
373    }
374 
375    @property void errCode(uint rhs) pure nothrow {
376       _errCode = rhs;
377    }
378 }