2 * This file is part of the libsigrokdecode project.
4 * Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libsigrokdecode.h"
27 * Error handling in libsigrokdecode.
31 * @defgroup grp_error Error handling
33 * Error handling in libsigrokdecode.
35 * libsigrokdecode functions usually return @ref SRD_OK upon success, or a
36 * negative error code on failure.
42 * Return a human-readable error string for the given libsigrokdecode error
45 * @param error_code A libsigrokdecode error code number, such as
48 * @return A const string containing a short, human-readable (English)
49 * description of the error, such as "memory allocation error".
50 * The string must NOT be free'd by the caller!
52 * @see srd_strerror_name
56 SRD_API const char *srd_strerror(int error_code)
61 * Note: All defined SRD_* error macros from libsigrokdecode.h must
62 * have an entry in this function, as well as in srd_strerror_name().
70 str = "generic/unspecified error";
73 str = "memory allocation error";
76 str = "invalid argument";
79 str = "internal error";
82 str = "Python API error";
84 case SRD_ERR_DECODERS_DIR:
85 str = "decoders directory access error";
88 str = "unknown error";
96 * Return the "name" string of the given libsigrokdecode error code.
98 * For example, the "name" of the SRD_ERR_MALLOC error code is
99 * "SRD_ERR_MALLOC", the name of the SRD_OK code is "SRD_OK", and so on.
101 * This function can be used for various purposes where the "name" string of
102 * a libsigrokdecode error code is useful.
104 * @param error_code A libsigrokdecode error code number, such as
107 * @return A const string containing the "name" of the error code as string.
108 * The string must NOT be free'd by the caller!
114 SRD_API const char *srd_strerror_name(int error_code)
119 * Note: All defined SRD_* error macros from libsigrokdecode.h must
120 * have an entry in this function, as well as in srd_strerror().
123 switch (error_code) {
131 str = "SRD_ERR_MALLOC";
140 str = "SRD_ERR_PYTHON";
142 case SRD_ERR_DECODERS_DIR:
143 str = "SRD_ERR_DECODERS_DIR";
146 str = "unknown error code";