XRootD
Loading...
Searching...
No Matches
XrdClStatus.cc
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3// Author: Lukasz Janyst <ljanyst@cern.ch>
4//------------------------------------------------------------------------------
5// XRootD is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// XRootD is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17//------------------------------------------------------------------------------
18
19#include "XrdCl/XrdClStatus.hh"
20#include "XrdSys/XrdSysE2T.hh"
22#include <cstring>
23
24namespace
25{
26 using namespace XrdCl;
27 struct ErrorMap
28 {
29 uint16_t code;
30 const char *msg;
31 };
32
33 ErrorMap errors[] = {
34 { errUnknown, "Unknown error" },
35 { errInvalidOp, "Invalid operation" },
36 { errFcntl, "Fcntl error" },
37 { errPoll, "Poll error" },
38 { errConfig, "Configuration error" },
39 { errInternal, "Internal error" },
40 { errUnknownCommand, "Command not found" },
41 { errInvalidArgs, "Invalid arguments" },
42 { errInProgress, "Operation in progress" },
43 { errUninitialized, "Initialization error" },
44 { errOSError, "OS Error" },
45 { errNotSupported, "Operation not supported" },
46 { errDataError, "Received corrupted data" },
47 { errNotImplemented, "Operation is not implemented" },
48 { errNoMoreReplicas, "No more replicas to try" },
49 { errPipelineFailed, "Pipeline failed" },
50 { errInvalidAddr, "Invalid address" },
51 { errSocketError, "Socket error" },
52 { errSocketTimeout, "Socket timeout" },
53 { errSocketDisconnected, "Socket disconnected" },
54 { errPollerError, "Poller error" },
55 { errSocketOptError, "Socket opt error" },
56 { errStreamDisconnect, "Stream disconnect" },
57 { errConnectionError, "Connection error" },
58 { errInvalidSession, "Invalid session" },
59 { errTlsError, "TLS error" },
60 { errInvalidMessage, "Invalid message" },
61 { errNotFound, "Resource not found" },
62 { errCheckSumError, "CheckSum error" },
63 { errRedirectLimit, "Redirect limit has been reached" },
64 { errHandShakeFailed, "Hand shake failed" },
65 { errLoginFailed, "Login failed" },
66 { errAuthFailed, "Auth failed" },
67 { errQueryNotSupported, "Query not supported" },
68 { errOperationExpired, "Operation expired" },
69 { errOperationInterrupted, "Operation interrupted" },
70 { errThresholdExceeded, "Threshold exceeded" },
71 { errNoMoreFreeSIDs, "No more free SIDs" },
72 { errInvalidRedirectURL, "Invalid redirect URL" },
73 { errInvalidResponse, "Invalid response" },
74 { errRedirect, "Unhandled redirect" },
75 { errErrorResponse, "Error response" },
76 { errLocalError, "Local error" },
77 { errResponseNegative, "Query response negative" },
78 { 0, 0 } };
79
80 //----------------------------------------------------------------------------
81 // Get error code
82 //----------------------------------------------------------------------------
83 std::string GetErrorMessage( uint16_t code )
84 {
85 for( int i = 0; errors[i].msg != 0; ++i )
86 if( errors[i].code == code )
87 return errors[i].msg;
88 return "Unknown error code";
89 }
90}
91
92namespace XrdCl
93{
94 //----------------------------------------------------------------------------
95 // Create a string representation
96 //----------------------------------------------------------------------------
97 std::string Status::ToString() const
98 {
99 std::ostringstream o;
100
101 //--------------------------------------------------------------------------
102 // The status is OK
103 //--------------------------------------------------------------------------
104 if( IsOK() )
105 {
106 o << "[SUCCESS] ";
107
108 if( code == suContinue )
109 o << "Continue";
110 else if( code == suRetry )
111 o << "Retry";
112
113 return o.str();
114 }
115
116 //--------------------------------------------------------------------------
117 // We have an error
118 //--------------------------------------------------------------------------
119 if( IsFatal() )
120 o << "[FATAL] ";
121 else
122 o << "[ERROR] ";
123
124 o << GetErrorMessage( code );
125
126 //--------------------------------------------------------------------------
127 // Add errno
128 //--------------------------------------------------------------------------
129 if( errNo >= kXR_ArgInvalid ) // kXR_ArgInvalid is the first (lowest) xrootd error code
130 // it is used in an inconsistent way sometimes it is
131 // xrootd error code and sometimes it is a plain errno
132 o << ": " << XrdSysE2T( XProtocol::toErrno( errNo ) );
133 else if ( errNo )
134 o << ": " << XrdSysE2T( errNo );
135
136 return o.str();
137 }
138}
@ kXR_ArgInvalid
Definition XProtocol.hh:990
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:99
static int toErrno(int xerr)
const uint16_t errPoll
error while polling descriptors
const uint16_t errUnknown
Unknown error.
const uint16_t suRetry
const uint16_t errQueryNotSupported
const uint16_t errInvalidAddr
const uint16_t errStreamDisconnect
const uint16_t errRedirectLimit
const uint16_t errUninitialized
const uint16_t errSocketOptError
const uint16_t errErrorResponse
const uint16_t errTlsError
const uint16_t errOperationExpired
const uint16_t errNotImplemented
Operation is not implemented.
const uint16_t errPollerError
const uint16_t errUnknownCommand
const uint16_t errResponseNegative
Query response was negative.
const uint16_t errLoginFailed
const uint16_t errNoMoreFreeSIDs
const uint16_t errInProgress
const uint16_t errNotFound
const uint16_t errSocketTimeout
const uint16_t errDataError
data is corrupted
const uint16_t errInternal
Internal error.
const uint16_t errInvalidOp
const uint16_t errHandShakeFailed
const uint16_t errConfig
System misconfigured.
const uint16_t errOSError
const uint16_t errPipelineFailed
Pipeline failed and operation couldn't be executed.
const uint16_t errInvalidResponse
const uint16_t errInvalidArgs
const uint16_t errInvalidRedirectURL
const uint16_t errConnectionError
const uint16_t errNotSupported
const uint16_t errLocalError
const uint16_t errSocketError
const uint16_t errCheckSumError
const uint16_t errThresholdExceeded
const uint16_t errOperationInterrupted
const uint16_t suContinue
const uint16_t errFcntl
failed manipulate file descriptor
const uint16_t errNoMoreReplicas
No more replicas to try.
const uint16_t errInvalidSession
const uint16_t errRedirect
const uint16_t errSocketDisconnected
const uint16_t errAuthFailed
const uint16_t errInvalidMessage
uint16_t code
Error type, or additional hints on what to do.
bool IsOK() const
We're fine.
bool IsFatal() const
Fatal error.
std::string ToString() const
Create a string representation.
uint32_t errNo
Errno, if any.