1c909a9f2ea6f99d0d3ac3efd5ae1114f576cd377Alex Vakulenko// Copyright 2014 The Chromium OS Authors. All rights reserved. 2c909a9f2ea6f99d0d3ac3efd5ae1114f576cd377Alex Vakulenko// Use of this source code is governed by a BSD-style license that can be 3c909a9f2ea6f99d0d3ac3efd5ae1114f576cd377Alex Vakulenko// found in the LICENSE file. 4c909a9f2ea6f99d0d3ac3efd5ae1114f576cd377Alex Vakulenko 59ed0cab99f18acb3570a35e9408f24355f6b8324Alex Vakulenko#include <brillo/errors/error_codes.h> 6c909a9f2ea6f99d0d3ac3efd5ae1114f576cd377Alex Vakulenko 7c9198057a8cc58342705c722ffac10f50df0040cAlex Vakulenko#include <base/posix/safe_strerror.h> 81015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko 99ed0cab99f18acb3570a35e9408f24355f6b8324Alex Vakulenkonamespace brillo { 10c909a9f2ea6f99d0d3ac3efd5ae1114f576cd377Alex Vakulenkonamespace errors { 11c909a9f2ea6f99d0d3ac3efd5ae1114f576cd377Alex Vakulenko 12e46e51f0af1c4b1f49da9019a2d71e96e484273bAlex Vakulenkonamespace dbus { 13e46e51f0af1c4b1f49da9019a2d71e96e484273bAlex Vakulenkoconst char kDomain[] = "dbus"; 14e46e51f0af1c4b1f49da9019a2d71e96e484273bAlex Vakulenko} // namespace dbus 15e46e51f0af1c4b1f49da9019a2d71e96e484273bAlex Vakulenko 16c909a9f2ea6f99d0d3ac3efd5ae1114f576cd377Alex Vakulenkonamespace json { 17c909a9f2ea6f99d0d3ac3efd5ae1114f576cd377Alex Vakulenkoconst char kDomain[] = "json_parser"; 18c909a9f2ea6f99d0d3ac3efd5ae1114f576cd377Alex Vakulenkoconst char kParseError[] = "json_parse_error"; 19c909a9f2ea6f99d0d3ac3efd5ae1114f576cd377Alex Vakulenkoconst char kObjectExpected[] = "json_object_expected"; 20c909a9f2ea6f99d0d3ac3efd5ae1114f576cd377Alex Vakulenko} // namespace json 21c909a9f2ea6f99d0d3ac3efd5ae1114f576cd377Alex Vakulenko 22df268d85ca937f52519b1a3214d3bc7a0306baeaAnton Muhinnamespace http { 23df268d85ca937f52519b1a3214d3bc7a0306baeaAnton Muhinconst char kDomain[] = "http"; 24df268d85ca937f52519b1a3214d3bc7a0306baeaAnton Muhin} // namespace http 25df268d85ca937f52519b1a3214d3bc7a0306baeaAnton Muhin 261015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenkonamespace system { 271015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenkoconst char kDomain[] = "system"; 281015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko 291015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenkonamespace { 301015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenkoconst struct ErrorMapEntry { 311015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko const char* error_code; 321015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko int errnum; 331015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko} error_map[] = { 341015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko#define ERROR_ENTRY(err) { #err, err } 351015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EPERM), // Operation not permitted 361015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOENT), // No such file or directory 371015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ESRCH), // No such process 381015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EINTR), // Interrupted system call 391015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EIO), // I/O error 401015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENXIO), // No such device or address 411015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(E2BIG), // Argument list too long 421015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOEXEC), // Exec format error 431015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EBADF), // Bad file number 441015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ECHILD), // No child processes 451015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EAGAIN), // Try again 461015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOMEM), // Out of memory 471015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EACCES), // Permission denied 481015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EFAULT), // Bad address 491015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOTBLK), // Block device required 501015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EBUSY), // Device or resource busy 511015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EEXIST), // File exists 521015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EXDEV), // Cross-device link 531015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENODEV), // No such device 541015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOTDIR), // Not a directory 551015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EISDIR), // Is a directory 561015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EINVAL), // Invalid argument 571015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENFILE), // File table overflow 581015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EMFILE), // Too many open files 591015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOTTY), // Not a typewriter 601015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ETXTBSY), // Text file busy 611015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EFBIG), // File too large 621015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOSPC), // No space left on device 631015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ESPIPE), // Illegal seek 641015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EROFS), // Read-only file system 651015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EMLINK), // Too many links 661015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EPIPE), // Broken pipe 671015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EDOM), // Math argument out of domain of func 681015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ERANGE), // Math result not representable 691015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EDEADLK), // Resource deadlock would occur 701015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENAMETOOLONG), // File name too long 711015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOLCK), // No record locks available 721015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOSYS), // Function not implemented 731015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOTEMPTY), // Directory not empty 741015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ELOOP), // Too many symbolic links encountered 751015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOMSG), // No message of desired type 761015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EIDRM), // Identifier removed 77c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#ifdef __linux__ 781015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ECHRNG), // Channel number out of range 791015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EL2NSYNC), // Level 2 not synchronized 801015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EL3HLT), // Level 3 halted 811015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EL3RST), // Level 3 reset 821015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ELNRNG), // Link number out of range 831015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EUNATCH), // Protocol driver not attached 841015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOCSI), // No CSI structure available 851015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EL2HLT), // Level 2 halted 861015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EBADE), // Invalid exchange 871015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EBADR), // Invalid request descriptor 881015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EXFULL), // Exchange full 891015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOANO), // No anode 901015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EBADRQC), // Invalid request code 911015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EBADSLT), // Invalid slot 921015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EBFONT), // Bad font file format 93c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#endif // __linux__ 941015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOSTR), // Device not a stream 951015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENODATA), // No data available 961015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ETIME), // Timer expired 971015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOSR), // Out of streams resources 98c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#ifdef __linux__ 991015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENONET), // Machine is not on the network 1001015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOPKG), // Package not installed 101c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#endif // __linux__ 1021015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EREMOTE), // Object is remote 1031015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOLINK), // Link has been severed 104c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#ifdef __linux__ 1051015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EADV), // Advertise error 1061015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ESRMNT), // Srmount error 1071015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ECOMM), // Communication error on send 108c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#endif // __linux__ 1091015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EPROTO), // Protocol error 1101015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EMULTIHOP), // Multihop attempted 111c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#ifdef __linux__ 1121015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EDOTDOT), // RFS specific error 113c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#endif // __linux__ 1141015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EBADMSG), // Not a data message 1151015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EOVERFLOW), // Value too large for defined data type 116c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#ifdef __linux__ 1171015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOTUNIQ), // Name not unique on network 1181015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EBADFD), // File descriptor in bad state 1191015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EREMCHG), // Remote address changed 1201015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ELIBACC), // Can not access a needed shared library 1211015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ELIBBAD), // Accessing a corrupted shared library 1221015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ELIBSCN), // .lib section in a.out corrupted 1231015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ELIBMAX), // Attempting to link in too many shared libs. 1241015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ELIBEXEC), // Cannot exec a shared library directly 125c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#endif // __linux__ 1261015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EILSEQ), // Illegal byte sequence 127c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#ifdef __linux__ 1281015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ERESTART), // Interrupted system call should be restarted 1291015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ESTRPIPE), // Streams pipe error 130c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#endif // __linux__ 1311015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EUSERS), // Too many users 1321015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOTSOCK), // Socket operation on non-socket 1331015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EDESTADDRREQ), // Destination address required 1341015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EMSGSIZE), // Message too long 1351015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EPROTOTYPE), // Protocol wrong type for socket 1361015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOPROTOOPT), // Protocol not available 1371015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EPROTONOSUPPORT), // Protocol not supported 1381015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ESOCKTNOSUPPORT), // Socket type not supported 1391015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EOPNOTSUPP), // Operation not supported o/transport endpoint 1401015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EPFNOSUPPORT), // Protocol family not supported 1411015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EAFNOSUPPORT), // Address family not supported by protocol 1421015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EADDRINUSE), // Address already in use 1431015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EADDRNOTAVAIL), // Cannot assign requested address 1441015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENETDOWN), // Network is down 1451015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENETUNREACH), // Network is unreachable 1461015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENETRESET), // Network dropped connection because of reset 1471015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ECONNABORTED), // Software caused connection abort 1481015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ECONNRESET), // Connection reset by peer 1491015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOBUFS), // No buffer space available 1501015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EISCONN), // Transport endpoint is already connected 1511015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOTCONN), // Transport endpoint is not connected 1521015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ESHUTDOWN), // Cannot send after transp. endpoint shutdown 1531015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ETOOMANYREFS), // Too many references: cannot splice 1541015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ETIMEDOUT), // Connection timed out 1551015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ECONNREFUSED), // Connection refused 1561015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EHOSTDOWN), // Host is down 1571015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EHOSTUNREACH), // No route to host 1581015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EALREADY), // Operation already in progress 1591015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EINPROGRESS), // Operation now in progress 1601015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ESTALE), // Stale file handle 161c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#ifdef __linux__ 1621015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EUCLEAN), // Structure needs cleaning 1631015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOTNAM), // Not a XENIX named type file 1641015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENAVAIL), // No XENIX semaphores available 1651015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EISNAM), // Is a named type file 1661015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EREMOTEIO), // Remote I/O error 167c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#endif // __linux__ 1681015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EDQUOT), // Quota exceeded 169c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#ifdef __linux__ 1701015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOMEDIUM), // No medium found 1711015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EMEDIUMTYPE), // Wrong medium type 172c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#endif // __linux__ 1731015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ECANCELED), // Operation Canceled 174c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#ifdef __linux__ 1751015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOKEY), // Required key not available 1761015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EKEYEXPIRED), // Key has expired 1771015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EKEYREVOKED), // Key has been revoked 1781015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EKEYREJECTED), // Key was rejected by service 179c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#endif // __linux__ 1801015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EOWNERDEAD), // Owner died 1811015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ENOTRECOVERABLE), // State not recoverable 182c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#ifdef __linux__ 1831015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(ERFKILL), // Operation not possible due to RF-kill 1841015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko ERROR_ENTRY(EHWPOISON), // Memory page has hardware error 185c2f4c40ed24d72fde8c26267d12fd6d0e84cdca5Scott James Remnant#endif // __linux__ 1861015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko#undef ERROR_ENTRY 1871015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko // This list comes from <errno.h> system header. The elements are ordered 1881015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko // by increasing errnum values which is the same order used in the header 1891015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko // file. So, when new error codes are added to glibc, it should be relatively 1901015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko // easy to identify them and add them to this list. 1911015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko}; 1921015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko 1931015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko// Gets the error code string from system error code. If unknown system error 1941015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko// number is provided, returns an empty string. 1951015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenkostd::string ErrorCodeFromSystemError(int errnum) { 1961015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko std::string error_code; 1971015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko for (const ErrorMapEntry& entry : error_map) { 1981015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko if (entry.errnum == errnum) { 1991015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko error_code = entry.error_code; 2001015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko break; 2011015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko } 2021015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko } 2031015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko return error_code; 2041015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko} 2051015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko 2061015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko} // anonymous namespace 2071015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko 2088f815f563c71645fd218977f16de8e746bec28a6Alex Vakulenkovoid AddSystemError(ErrorPtr* error, 2098f815f563c71645fd218977f16de8e746bec28a6Alex Vakulenko const tracked_objects::Location& location, 2108f815f563c71645fd218977f16de8e746bec28a6Alex Vakulenko int errnum) { 211c9198057a8cc58342705c722ffac10f50df0040cAlex Vakulenko std::string message = base::safe_strerror(errnum); 2121015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko std::string code = ErrorCodeFromSystemError(errnum); 2131015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko if (message.empty()) 2141015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko message = "Unknown error " + std::to_string(errnum); 2151015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko 2161015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko if (code.empty()) 2171015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko code = "error_" + std::to_string(errnum); 2181015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko 2198f815f563c71645fd218977f16de8e746bec28a6Alex Vakulenko Error::AddTo(error, location, kDomain, code, message); 2201015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko} 2211015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko 2221015de7bd4c83e0a5f0f1f4fda906001c85e924eAlex Vakulenko} // namespace system 223c909a9f2ea6f99d0d3ac3efd5ae1114f576cd377Alex Vakulenko 224c909a9f2ea6f99d0d3ac3efd5ae1114f576cd377Alex Vakulenko} // namespace errors 2259ed0cab99f18acb3570a35e9408f24355f6b8324Alex Vakulenko} // namespace brillo 226