1 /*
2  *  error.c
3  *
4  *  Copyright (c) 2006-2018 Pacman Development Team <pacman-dev@archlinux.org>
5  *  Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifdef HAVE_LIBCURL
22 #include <curl/curl.h>
23 #endif
24 
25 /* libalpm */
26 #include "util.h"
27 #include "alpm.h"
28 #include "handle.h"
29 
alpm_errno(alpm_handle_t * handle)30 alpm_errno_t SYMEXPORT alpm_errno(alpm_handle_t *handle)
31 {
32 	return handle->pm_errno;
33 }
34 
alpm_strerror(alpm_errno_t err)35 const char SYMEXPORT *alpm_strerror(alpm_errno_t err)
36 {
37 	switch(err) {
38 		/* System */
39 		case ALPM_ERR_MEMORY:
40 			return _("out of memory!");
41 		case ALPM_ERR_SYSTEM:
42 			return _("unexpected system error");
43 		case ALPM_ERR_BADPERMS:
44 			return _("permission denied");
45 		case ALPM_ERR_NOT_A_FILE:
46 			return _("could not find or read file");
47 		case ALPM_ERR_NOT_A_DIR:
48 			return _("could not find or read directory");
49 		case ALPM_ERR_WRONG_ARGS:
50 			return _("wrong or NULL argument passed");
51 		case ALPM_ERR_DISK_SPACE:
52 			return _("not enough free disk space");
53 		/* Interface */
54 		case ALPM_ERR_HANDLE_NULL:
55 			return _("library not initialized");
56 		case ALPM_ERR_HANDLE_NOT_NULL:
57 			return _("library already initialized");
58 		case ALPM_ERR_HANDLE_LOCK:
59 			return _("unable to lock database");
60 		/* Databases */
61 		case ALPM_ERR_DB_OPEN:
62 			return _("could not open database");
63 		case ALPM_ERR_DB_CREATE:
64 			return _("could not create database");
65 		case ALPM_ERR_DB_NULL:
66 			return _("database not initialized");
67 		case ALPM_ERR_DB_NOT_NULL:
68 			return _("database already registered");
69 		case ALPM_ERR_DB_NOT_FOUND:
70 			return _("could not find database");
71 		case ALPM_ERR_DB_INVALID:
72 			return _("invalid or corrupted database");
73 		case ALPM_ERR_DB_INVALID_SIG:
74 			return _("invalid or corrupted database (PGP signature)");
75 		case ALPM_ERR_DB_VERSION:
76 			return _("database is incorrect version");
77 		case ALPM_ERR_DB_WRITE:
78 			return _("could not update database");
79 		case ALPM_ERR_DB_REMOVE:
80 			return _("could not remove database entry");
81 		/* Servers */
82 		case ALPM_ERR_SERVER_BAD_URL:
83 			return _("invalid url for server");
84 		case ALPM_ERR_SERVER_NONE:
85 			return _("no servers configured for repository");
86 		/* Transactions */
87 		case ALPM_ERR_TRANS_NOT_NULL:
88 			return _("transaction already initialized");
89 		case ALPM_ERR_TRANS_NULL:
90 			return _("transaction not initialized");
91 		case ALPM_ERR_TRANS_DUP_TARGET:
92 			return _("duplicate target");
93 		case ALPM_ERR_TRANS_NOT_INITIALIZED:
94 			return _("transaction not initialized");
95 		case ALPM_ERR_TRANS_NOT_PREPARED:
96 			return _("transaction not prepared");
97 		case ALPM_ERR_TRANS_ABORT:
98 			return _("transaction aborted");
99 		case ALPM_ERR_TRANS_TYPE:
100 			return _("operation not compatible with the transaction type");
101 		case ALPM_ERR_TRANS_NOT_LOCKED:
102 			return _("transaction commit attempt when database is not locked");
103 		case ALPM_ERR_TRANS_HOOK_FAILED:
104 			return _("failed to run transaction hooks");
105 		/* Packages */
106 		case ALPM_ERR_PKG_NOT_FOUND:
107 			return _("could not find or read package");
108 		case ALPM_ERR_PKG_IGNORED:
109 			return _("operation cancelled due to ignorepkg");
110 		case ALPM_ERR_PKG_INVALID:
111 			return _("invalid or corrupted package");
112 		case ALPM_ERR_PKG_INVALID_CHECKSUM:
113 			return _("invalid or corrupted package (checksum)");
114 		case ALPM_ERR_PKG_INVALID_SIG:
115 			return _("invalid or corrupted package (PGP signature)");
116 		case ALPM_ERR_PKG_MISSING_SIG:
117 			return _("package missing required signature");
118 		case ALPM_ERR_PKG_OPEN:
119 			return _("cannot open package file");
120 		case ALPM_ERR_PKG_CANT_REMOVE:
121 			return _("cannot remove all files for package");
122 		case ALPM_ERR_PKG_INVALID_NAME:
123 			return _("package filename is not valid");
124 		case ALPM_ERR_PKG_INVALID_ARCH:
125 			return _("package architecture is not valid");
126 		case ALPM_ERR_PKG_REPO_NOT_FOUND:
127 			return _("could not find repository for target");
128 		/* Signatures */
129 		case ALPM_ERR_SIG_MISSING:
130 			return _("missing PGP signature");
131 		case ALPM_ERR_SIG_INVALID:
132 			return _("invalid PGP signature");
133 		/* Deltas */
134 		case ALPM_ERR_DLT_INVALID:
135 			return _("invalid or corrupted delta");
136 		case ALPM_ERR_DLT_PATCHFAILED:
137 			return _("delta patch failed");
138 		/* Dependencies */
139 		case ALPM_ERR_UNSATISFIED_DEPS:
140 			return _("could not satisfy dependencies");
141 		case ALPM_ERR_CONFLICTING_DEPS:
142 			return _("conflicting dependencies");
143 		case ALPM_ERR_FILE_CONFLICTS:
144 			return _("conflicting files");
145 		/* Miscellaenous */
146 		case ALPM_ERR_RETRIEVE:
147 			return _("failed to retrieve some files");
148 		case ALPM_ERR_INVALID_REGEX:
149 			return _("invalid regular expression");
150 		/* Errors from external libraries- our own wrapper error */
151 		case ALPM_ERR_LIBARCHIVE:
152 			/* it would be nice to use archive_error_string() here, but that
153 			 * requires the archive struct, so we can't. Just use a generic
154 			 * error string instead. */
155 			return _("libarchive error");
156 		case ALPM_ERR_LIBCURL:
157 			return _("download library error");
158 		case ALPM_ERR_GPGME:
159 			return _("gpgme error");
160 		case ALPM_ERR_EXTERNAL_DOWNLOAD:
161 			return _("error invoking external downloader");
162 		/* Unknown error! */
163 		default:
164 			return _("unexpected error");
165 	}
166 }
167