Directory: | cvmfs/ |
---|---|
File: | cvmfs/network/network_errors.h |
Date: | 2025-02-09 02:34:19 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 36 | 36 | 100.0% |
Branches: | 4 | 4 | 100.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /** | ||
2 | * This file is part of the CernVM File System. | ||
3 | */ | ||
4 | |||
5 | #ifndef CVMFS_NETWORK_NETWORK_ERRORS_H_ | ||
6 | #define CVMFS_NETWORK_NETWORK_ERRORS_H_ | ||
7 | |||
8 | namespace download { | ||
9 | |||
10 | /** | ||
11 | * Possible return values. Adjust ObjectFetcher error handling if new network | ||
12 | * error conditions are added. | ||
13 | */ | ||
14 | enum Failures { | ||
15 | kFailOk = 0, | ||
16 | kFailLocalIO, | ||
17 | kFailBadUrl, | ||
18 | kFailProxyResolve, | ||
19 | kFailHostResolve, | ||
20 | // artificial failure code. Try other host even though | ||
21 | // failure seems to be at the proxy | ||
22 | kFailHostAfterProxy, | ||
23 | kFailProxyConnection, | ||
24 | kFailHostConnection, | ||
25 | kFailProxyHttp, | ||
26 | kFailHostHttp, | ||
27 | kFailBadData, | ||
28 | kFailTooBig, | ||
29 | kFailOther, | ||
30 | kFailUnsupportedProtocol, | ||
31 | kFailProxyTooSlow, | ||
32 | kFailHostTooSlow, | ||
33 | kFailProxyShortTransfer, | ||
34 | kFailHostShortTransfer, | ||
35 | kFailCanceled, | ||
36 | |||
37 | kFailNumEntries | ||
38 | }; // Failures | ||
39 | |||
40 | |||
41 | 107 | inline bool IsHostTransferError(const Failures error) { | |
42 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 80 times.
|
107 | switch (error) { |
43 | 27 | case kFailHostConnection: | |
44 | case kFailHostTooSlow: | ||
45 | case kFailHostShortTransfer: | ||
46 | 27 | return true; | |
47 | 80 | default: | |
48 | 80 | break; | |
49 | } | ||
50 | 80 | return false; | |
51 | } | ||
52 | |||
53 | 108 | inline bool IsProxyTransferError(const Failures error) { | |
54 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 106 times.
|
108 | switch (error) { |
55 | 2 | case kFailProxyConnection: | |
56 | case kFailProxyTooSlow: | ||
57 | case kFailProxyShortTransfer: | ||
58 | 2 | return true; | |
59 | 106 | default: | |
60 | 106 | break; | |
61 | } | ||
62 | 106 | return false; | |
63 | } | ||
64 | |||
65 | 31 | inline const char *Code2Ascii(const Failures error) { | |
66 | const char *texts[kFailNumEntries + 1]; | ||
67 | 31 | texts[0] = "OK"; | |
68 | 31 | texts[1] = "local I/O failure"; | |
69 | 31 | texts[2] = "malformed URL"; | |
70 | 31 | texts[3] = "failed to resolve proxy address"; | |
71 | 31 | texts[4] = "failed to resolve host address"; | |
72 | 31 | texts[5] = "all proxies failed, trying host fail-over"; | |
73 | 31 | texts[6] = "proxy connection problem"; | |
74 | 31 | texts[7] = "host connection problem"; | |
75 | 31 | texts[8] = "proxy returned HTTP error"; | |
76 | 31 | texts[9] = "host returned HTTP error"; | |
77 | 31 | texts[10] = "corrupted data received"; | |
78 | 31 | texts[11] = "resource too big to download"; | |
79 | 31 | texts[12] = "unknown network error"; | |
80 | 31 | texts[13] = "Unsupported URL in protocol"; | |
81 | 31 | texts[14] = "proxy serving data too slowly"; | |
82 | 31 | texts[15] = "host serving data too slowly"; | |
83 | 31 | texts[16] = "proxy data transfer cut short"; | |
84 | 31 | texts[17] = "host data transfer cut short"; | |
85 | 31 | texts[18] = "request canceled"; | |
86 | 31 | texts[19] = "no text"; | |
87 | 31 | return texts[error]; | |
88 | } | ||
89 | |||
90 | } // namespace download | ||
91 | |||
92 | #endif // CVMFS_NETWORK_NETWORK_ERRORS_H_ | ||
93 |