Merge lp:~mandel/ubuntu-download-manager/better-error-logging into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Approved by: Oliver Grawert
Approved revision: 330
Merged at revision: 316
Proposed branch: lp:~mandel/ubuntu-download-manager/better-error-logging
Merge into: lp:ubuntu-download-manager
Prerequisite: lp:~mandel/ubuntu-download-manager/fix-uploads-timeout
Diff against target: 261 lines (+193/-6)
3 files modified
src/common/public/ubuntu/transfers/system/logger.cpp (+2/-2)
src/downloads/priv/ubuntu/downloads/file_download.cpp (+98/-4)
src/uploads/priv/ubuntu/uploads/file_upload.cpp (+93/-0)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/better-error-logging
Reviewer Review Type Date Requested Status
Oliver Grawert Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+227544@code.launchpad.net

Commit message

Fix bug 1346196 by using human readable strings.

Description of the change

The code is duplicated and not present in src/common/public/ubuntu/transfers/system/logger.cpp so that we do not expose QNetwork to the user of the client lib.

To post a comment you must log in.
330. By Manuel de la Peña

Fix tabbing.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Oliver Grawert (ogra) wrote :

looks fine

Revision history for this message
Oliver Grawert (ogra) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/common/public/ubuntu/transfers/system/logger.cpp'
2--- src/common/public/ubuntu/transfers/system/logger.cpp 2014-07-21 12:38:46 +0000
3+++ src/common/public/ubuntu/transfers/system/logger.cpp 2014-07-21 12:38:46 +0000
4@@ -91,7 +91,7 @@
5 }
6
7 namespace {
8- const QString LOG_NAME = "ubuntu-download-manager.log";
9+ const QString LOG_NAME = QCoreApplication::instance()->applicationName() + ".log";
10 }
11
12 namespace Ubuntu {
13@@ -139,7 +139,7 @@
14 Logger::getLogDir() {
15 QString path = "";
16 if (getuid() == 0) {
17- path = "/var/log/ubuntu-download-manager";
18+ path = "/var/log/" + QCoreApplication::instance()->applicationName();
19 } else {
20 path = QStandardPaths::writableLocation(
21 QStandardPaths::CacheLocation);
22
23=== modified file 'src/downloads/priv/ubuntu/downloads/file_download.cpp'
24--- src/downloads/priv/ubuntu/downloads/file_download.cpp 2014-07-21 12:38:46 +0000
25+++ src/downloads/priv/ubuntu/downloads/file_download.cpp 2014-07-21 12:38:46 +0000
26@@ -24,6 +24,7 @@
27 #include <QFileInfo>
28 #include <QSslError>
29 #include <glog/logging.h>
30+#include <map>
31 #include <ubuntu/transfers/system/hash_algorithm.h>
32 #include <ubuntu/transfers/system/cryptographic_hash.h>
33 #include <ubuntu/transfers/system/logger.h>
34@@ -36,6 +37,99 @@
35 #define DOWN_LOG(LEVEL) LOG(LEVEL) << ((parent() != nullptr)?"GroupDownload {" + parent()->objectName() + " } ":"") << "Download ID{" << objectName() << " } "
36
37
38+std::ostream& operator<<(std::ostream &out, QNetworkReply::NetworkError err) {
39+ static std::map<QNetworkReply::NetworkError, std::string> errorsMap {
40+ {QNetworkReply::ConnectionRefusedError, "ConnectionRefusedError: the remote "
41+ "server refused the connection (the server is not accepting "
42+ "requests)"},
43+ {QNetworkReply::RemoteHostClosedError, "RemoteHostClosedError: the remote "
44+ "server closed the connection prematurely, before the entire reply "
45+ "was received and processed"},
46+ {QNetworkReply::HostNotFoundError, "HostNotFoundError: the remote host name "
47+ "was not found (invalid hostname)"},
48+ {QNetworkReply::TimeoutError, "TimeoutError: the connection to the remote "
49+ "server timed out"},
50+ {QNetworkReply::OperationCanceledError, "OperationCanceledError: the "
51+ "operation was canceled via calls to abort() or close() before "
52+ "it was finished."},
53+ {QNetworkReply::SslHandshakeFailedError, "SslHandshakeFailedError: the "
54+ "SSL/TLS handshake failed and the encrypted channel could not "
55+ "be established."},
56+ {QNetworkReply::TemporaryNetworkFailureError, "TemporaryNetworkFailureError: "
57+ "the connection was broken "
58+ "due to disconnection from the network, however the system has "
59+ "initiated roaming to another access point. The request should be "
60+ "resubmitted and will be processed as soon as the connection is "
61+ "re-established."},
62+ {QNetworkReply::NetworkSessionFailedError, "NetworkSessionFailedError: the "
63+ "connection was broken due to disconnection from the network or "
64+ "failure to start the network."},
65+ {QNetworkReply::BackgroundRequestNotAllowedError,
66+ "BackgroundRequestNotAllowedError: the background request is "
67+ "not currently allowed due to platform policy."},
68+ {QNetworkReply::ProxyConnectionRefusedError, "ProxyConnectionRefusedError: "
69+ "the connection to the proxy server was refused (the proxy server "
70+ "is not accepting requests)"},
71+ {QNetworkReply::ProxyConnectionClosedError, "ProxyConnectionClosedError: the "
72+ "proxy server closed the connection prematurely, before the entire "
73+ "reply was received and processed"},
74+ {QNetworkReply::ProxyNotFoundError, "ProxyNotFoundError: the proxy host name "
75+ "was not found (invalid proxy hostname)"},
76+ {QNetworkReply::ProxyTimeoutError, "ProxyTimeoutError: the connection to "
77+ "the proxy timed out or the proxy did not reply in time to the "
78+ "request sent"},
79+ {QNetworkReply::ProxyAuthenticationRequiredError,
80+ "ProxyAuthenticationRequiredError: the proxy requires "
81+ "authentication in order to honour the request but did not accept "
82+ "any credentials offered (if any)"},
83+ {QNetworkReply::ContentAccessDenied, "ContentAccessDenied: the access to "
84+ "the remote content was denied (similar to HTTP error 401)"},
85+ {QNetworkReply::ContentOperationNotPermittedError,
86+ "ContentOperationNotPermittedError: the operation requested "
87+ "on the remote content is not permitted"},
88+ {QNetworkReply::ContentNotFoundError, "ContentNotFoundError: the remote "
89+ "content was not found at the server (similar to HTTP error 404)"},
90+ {QNetworkReply::AuthenticationRequiredError, "AuthenticationRequiredError: "
91+ "the remote server requires authentication to serve the content "
92+ "but the credentials provided were not accepted (if any)."},
93+ {QNetworkReply::ContentReSendError, "ContentReSendError: the request needed "
94+ "to be sent again, but this failed for example because the upload "
95+ "data could not be read a second time."},
96+ {QNetworkReply::ContentConflictError, "ContentConflictError: the request "
97+ "could not be completed due to a conflict with the current state "
98+ "of the resource."},
99+ {QNetworkReply::ContentGoneError, "ContentGoneError: the requested resource "
100+ "is no longer available at the server."},
101+ {QNetworkReply::InternalServerError, "InternalServerError: the server "
102+ "encountered an unexpected condition which prevented it from "
103+ "fulfilling the request."},
104+ {QNetworkReply::OperationNotImplementedError,
105+ "OperationNotImplementedError: the server does not support "
106+ "the functionality required to fulfill the request."},
107+ {QNetworkReply::ServiceUnavailableError, "ServiceUnavailableError: the "
108+ "server is unable to handle the request at this time."},
109+ {QNetworkReply::ProtocolUnknownError, "ProtocolUnknownError: the Network "
110+ "Access API cannot honor the request because the protocol "
111+ "is not known"},
112+ {QNetworkReply::ProtocolInvalidOperationError,
113+ "ProtocolInvalidOperationError: the requested operation is "
114+ "invalid for this protocol"},
115+ {QNetworkReply::UnknownNetworkError,
116+ "UnknownNetworkError: an unknown network-related error was "
117+ "detected"},
118+ {QNetworkReply::UnknownProxyError, "UnknownProxyError: an unknown "
119+ "proxy-related error was detected"},
120+ {QNetworkReply::UnknownContentError, "UnknownContentError: an unknown "
121+ "error related to the remote content was detected"},
122+ {QNetworkReply::ProtocolFailure, "ProtocolFailure: a breakdown in protocol "
123+ "was detected (parsing error, invalid or unexpected responses, etc.)"},
124+ {QNetworkReply::UnknownServerError, "UnknownServerError: an unknown error "
125+ "related to the server response was detected"}
126+ };
127+ out << "Network error " << errorsMap[err];
128+ return out;
129+}
130+
131 namespace {
132
133 const QString DATA_FILE_NAME = "data.download";
134@@ -723,11 +817,11 @@
135 DOWN_LOG(INFO) << "Rename '" << _tempFilePath << "' to '"
136 << _filePath << "'";
137 QFile tempFile(_tempFilePath);
138- auto r = tempFile.rename(_filePath);
139- if (!r) {
140+ auto r = tempFile.rename(_filePath);
141+ if (!r) {
142 DOWN_LOG(WARNING) << "Could not rename '" << _tempFilePath << "' to '"
143 << _filePath << "' due to " << tempFile.errorString();
144- }
145+ }
146 }
147
148 setState(Download::FINISH);
149@@ -741,7 +835,7 @@
150 FileDownload::unlockFilePath() {
151 if (!isConfined() && metadata().contains(Metadata::LOCAL_PATH_KEY)) {
152 _fileNameMutex->unlockFileName(_tempFilePath);
153- } else {
154+ } else {
155 _fileNameMutex->unlockFileName(_filePath);
156 }
157 }
158
159=== modified file 'src/uploads/priv/ubuntu/uploads/file_upload.cpp'
160--- src/uploads/priv/ubuntu/uploads/file_upload.cpp 2014-07-21 12:38:46 +0000
161+++ src/uploads/priv/ubuntu/uploads/file_upload.cpp 2014-07-21 12:38:46 +0000
162@@ -25,6 +25,99 @@
163
164 #define UP_LOG(LEVEL) LOG(LEVEL) << "Upload ID{" << objectName() << " } "
165
166+std::ostream& operator<<(std::ostream &out, QNetworkReply::NetworkError err) {
167+ static std::map<QNetworkReply::NetworkError, std::string> errorsMap {
168+ {QNetworkReply::ConnectionRefusedError, "ConnectionRefusedError: the remote "
169+ "server refused the connection (the server is not accepting "
170+ "requests)"},
171+ {QNetworkReply::RemoteHostClosedError, "RemoteHostClosedError: the remote "
172+ "server closed the connection prematurely, before the entire reply "
173+ "was received and processed"},
174+ {QNetworkReply::HostNotFoundError, "HostNotFoundError: the remote host name "
175+ "was not found (invalid hostname)"},
176+ {QNetworkReply::TimeoutError, "TimeoutError: the connection to the remote "
177+ "server timed out"},
178+ {QNetworkReply::OperationCanceledError, "OperationCanceledError: the "
179+ "operation was canceled via calls to abort() or close() before "
180+ "it was finished."},
181+ {QNetworkReply::SslHandshakeFailedError, "SslHandshakeFailedError: the "
182+ "SSL/TLS handshake failed and the encrypted channel could not "
183+ "be established."},
184+ {QNetworkReply::TemporaryNetworkFailureError, "TemporaryNetworkFailureError: "
185+ "the connection was broken "
186+ "due to disconnection from the network, however the system has "
187+ "initiated roaming to another access point. The request should be "
188+ "resubmitted and will be processed as soon as the connection is "
189+ "re-established."},
190+ {QNetworkReply::NetworkSessionFailedError, "NetworkSessionFailedError: the "
191+ "connection was broken due to disconnection from the network or "
192+ "failure to start the network."},
193+ {QNetworkReply::BackgroundRequestNotAllowedError,
194+ "BackgroundRequestNotAllowedError: the background request is "
195+ "not currently allowed due to platform policy."},
196+ {QNetworkReply::ProxyConnectionRefusedError, "ProxyConnectionRefusedError: "
197+ "the connection to the proxy server was refused (the proxy server "
198+ "is not accepting requests)"},
199+ {QNetworkReply::ProxyConnectionClosedError, "ProxyConnectionClosedError: the "
200+ "proxy server closed the connection prematurely, before the entire "
201+ "reply was received and processed"},
202+ {QNetworkReply::ProxyNotFoundError, "ProxyNotFoundError: the proxy host name "
203+ "was not found (invalid proxy hostname)"},
204+ {QNetworkReply::ProxyTimeoutError, "ProxyTimeoutError: the connection to "
205+ "the proxy timed out or the proxy did not reply in time to the "
206+ "request sent"},
207+ {QNetworkReply::ProxyAuthenticationRequiredError,
208+ "ProxyAuthenticationRequiredError: the proxy requires "
209+ "authentication in order to honour the request but did not accept "
210+ "any credentials offered (if any)"},
211+ {QNetworkReply::ContentAccessDenied, "ContentAccessDenied: the access to "
212+ "the remote content was denied (similar to HTTP error 401)"},
213+ {QNetworkReply::ContentOperationNotPermittedError,
214+ "ContentOperationNotPermittedError: the operation requested "
215+ "on the remote content is not permitted"},
216+ {QNetworkReply::ContentNotFoundError, "ContentNotFoundError: the remote "
217+ "content was not found at the server (similar to HTTP error 404)"},
218+ {QNetworkReply::AuthenticationRequiredError, "AuthenticationRequiredError: "
219+ "the remote server requires authentication to serve the content "
220+ "but the credentials provided were not accepted (if any)."},
221+ {QNetworkReply::ContentReSendError, "ContentReSendError: the request needed "
222+ "to be sent again, but this failed for example because the upload "
223+ "data could not be read a second time."},
224+ {QNetworkReply::ContentConflictError, "ContentConflictError: the request "
225+ "could not be completed due to a conflict with the current state "
226+ "of the resource."},
227+ {QNetworkReply::ContentGoneError, "ContentGoneError: the requested resource "
228+ "is no longer available at the server."},
229+ {QNetworkReply::InternalServerError, "InternalServerError: the server "
230+ "encountered an unexpected condition which prevented it from "
231+ "fulfilling the request."},
232+ {QNetworkReply::OperationNotImplementedError,
233+ "OperationNotImplementedError: the server does not support "
234+ "the functionality required to fulfill the request."},
235+ {QNetworkReply::ServiceUnavailableError, "ServiceUnavailableError: the "
236+ "server is unable to handle the request at this time."},
237+ {QNetworkReply::ProtocolUnknownError, "ProtocolUnknownError: the Network "
238+ "Access API cannot honor the request because the protocol "
239+ "is not known"},
240+ {QNetworkReply::ProtocolInvalidOperationError,
241+ "ProtocolInvalidOperationError: the requested operation is "
242+ "invalid for this protocol"},
243+ {QNetworkReply::UnknownNetworkError,
244+ "UnknownNetworkError: an unknown network-related error was "
245+ "detected"},
246+ {QNetworkReply::UnknownProxyError, "UnknownProxyError: an unknown "
247+ "proxy-related error was detected"},
248+ {QNetworkReply::UnknownContentError, "UnknownContentError: an unknown "
249+ "error related to the remote content was detected"},
250+ {QNetworkReply::ProtocolFailure, "ProtocolFailure: a breakdown in protocol "
251+ "was detected (parsing error, invalid or unexpected responses, etc.)"},
252+ {QNetworkReply::UnknownServerError, "UnknownServerError: an unknown error "
253+ "related to the server response was detected"}
254+ };
255+ out << "Network error " << errorsMap[err];
256+ return out;
257+}
258+
259 namespace {
260 const QString CONTENT_TYPE_HEADER = "multipart/form-data;";
261 const QString NETWORK_ERROR = "NETWORK ERROR";

Subscribers

People subscribed via source and target branches