2 * Copyright (C) <2003> David A. Schleef <ds@schleef.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 * @short_description: Categorized error messages
23 * @see_also: #GstMessage
25 * GStreamer elements can throw non-fatal warnings and fatal errors.
26 * Higher-level elements and applications can programmatically filter
27 * the ones they are interested in or can recover from,
28 * and have a default handler handle the rest of them.
30 * The rest of this section will use the term <quote>error</quote>
31 * to mean both (non-fatal) warnings and (fatal) errors; they are treated
34 * Errors from elements are the combination of a #GError and a debug string.
35 * The #GError contains:
36 * - a domain type: CORE, LIBRARY, RESOURCE or STREAM
37 * - a code: an enum value specific to the domain
38 * - a translated, human-readable message
39 * - a non-translated additional debug string, which also contains
40 * - file and line information
42 * Elements do not have the context required to decide what to do with
43 * errors. As such, they should only inform about errors, and stop their
44 * processing. In short, an element doesn't know what it is being used for.
46 * It is the application or compound element using the given element that
47 * has more context about the use of the element. Errors can be received by
48 * listening to the #GstBus of the element/pipeline for #GstMessage objects with
49 * the type %GST_MESSAGE_ERROR or %GST_MESSAGE_WARNING. The thrown errors should
50 * be inspected, and filtered if appropriate.
52 * An application is expected to, by default, present the user with a
53 * dialog box (or an equivalent) showing the error message. The dialog
54 * should also allow a way to get at the additional debug information,
55 * so the user can provide bug reporting information.
57 * A compound element is expected to forward errors by default higher up
58 * the hierarchy; this is done by default in the same way as for other types
61 * When applications or compound elements trigger errors that they can
62 * recover from, they can filter out these errors and take appropriate action.
63 * For example, an application that gets an error from xvimagesink
64 * that indicates all XVideo ports are taken, the application can attempt
65 * to use another sink instead.
67 * Elements throw errors using the #GST_ELEMENT_ERROR convenience macro:
70 * <title>Throwing an error</title>
72 * GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
73 * (_("No file name specified for reading.")), (NULL));
77 * Things to keep in mind:
79 * <listitem><para>Don't go off inventing new error codes. The ones
80 * currently provided should be enough. If you find your type of error
81 * does not fit the current codes, you should use FAILED.</para></listitem>
82 * <listitem><para>Don't provide a message if the default one suffices.
83 * this keeps messages more uniform. Use (%NULL) - not forgetting the
84 * parentheses.</para></listitem>
85 * <listitem><para>If you do supply a custom message, it should be
86 * marked for translation. The message should start with a capital
87 * and end with a period. The message should describe the error in short,
88 * in a human-readable form, and without any complex technical terms.
89 * A user interface will present this message as the first thing a user
90 * sees. Details, technical info, ... should go in the debug string.
92 * <listitem><para>The debug string can be as you like. Again, use (%NULL)
93 * if there's nothing to add - file and line number will still be
94 * passed. #GST_ERROR_SYSTEM can be used as a shortcut to give
95 * debug information on a system call error.</para></listitem>
99 /* FIXME 2.0: the entire error system needs an overhaul - it's not very
100 * useful the way it is. Also, we need to be able to specify additional
101 * 'details' for errors (e.g. disk/file/resource error -> out-of-space; or
102 * put the url/filename/device name that caused the error somewhere)
103 * without having to add enums for every little thing.
105 * FIXME 2.0: get rid of GST_{CORE,LIBRARY,RESOURCE,STREAM}_ERROR_NUM_ERRORS.
106 * Maybe also replace _quark() functions with g_quark_from_static_string()?
112 #include "gst_private.h"
114 #include "gst-i18n-lib.h"
116 #define QUARK_FUNC(string) \
117 GQuark gst_ ## string ## _error_quark (void) { \
118 static GQuark quark; \
120 quark = g_quark_from_static_string ("gst-" # string "-error-quark"); \
123 #define FILE_A_BUG " Please file a bug at " PACKAGE_BUGREPORT "."
126 gst_error_get_core_error (GstCoreError code)
129 case GST_CORE_ERROR_FAILED:
130 return _("GStreamer encountered a general core library error.");
131 case GST_CORE_ERROR_TOO_LAZY:
132 return _("GStreamer developers were too lazy to assign an error code "
133 "to this error." FILE_A_BUG);
134 case GST_CORE_ERROR_NOT_IMPLEMENTED:
135 return _("Internal GStreamer error: code not implemented." FILE_A_BUG);
136 case GST_CORE_ERROR_STATE_CHANGE:
137 return _("GStreamer error: state change failed and some element failed "
138 "to post a proper error message with the reason for the failure.");
139 case GST_CORE_ERROR_PAD:
140 return _("Internal GStreamer error: pad problem." FILE_A_BUG);
141 case GST_CORE_ERROR_THREAD:
142 return _("Internal GStreamer error: thread problem." FILE_A_BUG);
143 case GST_CORE_ERROR_NEGOTIATION:
144 return _("GStreamer error: negotiation problem.");
145 case GST_CORE_ERROR_EVENT:
146 return _("Internal GStreamer error: event problem." FILE_A_BUG);
147 case GST_CORE_ERROR_SEEK:
148 return _("Internal GStreamer error: seek problem." FILE_A_BUG);
149 case GST_CORE_ERROR_CAPS:
150 return _("Internal GStreamer error: caps problem." FILE_A_BUG);
151 case GST_CORE_ERROR_TAG:
152 return _("Internal GStreamer error: tag problem." FILE_A_BUG);
153 case GST_CORE_ERROR_MISSING_PLUGIN:
154 return _("Your GStreamer installation is missing a plug-in.");
155 case GST_CORE_ERROR_CLOCK:
156 return _("GStreamer error: clock problem.");
157 case GST_CORE_ERROR_DISABLED:
158 return _("This application is trying to use GStreamer functionality "
159 "that has been disabled.");
160 case GST_CORE_ERROR_NUM_ERRORS:
168 gst_error_get_library_error (GstLibraryError code)
171 case GST_LIBRARY_ERROR_FAILED:
172 return _("GStreamer encountered a general supporting library error.");
173 case GST_LIBRARY_ERROR_TOO_LAZY:
174 return _("GStreamer developers were too lazy to assign an error code "
175 "to this error." FILE_A_BUG);
176 case GST_LIBRARY_ERROR_INIT:
177 return _("Could not initialize supporting library.");
178 case GST_LIBRARY_ERROR_SHUTDOWN:
179 return _("Could not close supporting library.");
180 case GST_LIBRARY_ERROR_SETTINGS:
181 return _("Could not configure supporting library.");
182 case GST_LIBRARY_ERROR_ENCODE:
183 return _("Encoding error.");
184 case GST_LIBRARY_ERROR_NUM_ERRORS:
192 gst_error_get_resource_error (GstResourceError code)
195 case GST_RESOURCE_ERROR_FAILED:
196 return _("GStreamer encountered a general resource error.");
197 case GST_RESOURCE_ERROR_TOO_LAZY:
198 return _("GStreamer developers were too lazy to assign an error code "
199 "to this error." FILE_A_BUG);
200 case GST_RESOURCE_ERROR_NOT_FOUND:
201 return _("Resource not found.");
202 case GST_RESOURCE_ERROR_BUSY:
203 return _("Resource busy or not available.");
204 case GST_RESOURCE_ERROR_OPEN_READ:
205 return _("Could not open resource for reading.");
206 case GST_RESOURCE_ERROR_OPEN_WRITE:
207 return _("Could not open resource for writing.");
208 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
209 return _("Could not open resource for reading and writing.");
210 case GST_RESOURCE_ERROR_CLOSE:
211 return _("Could not close resource.");
212 case GST_RESOURCE_ERROR_READ:
213 return _("Could not read from resource.");
214 case GST_RESOURCE_ERROR_WRITE:
215 return _("Could not write to resource.");
216 case GST_RESOURCE_ERROR_SEEK:
217 return _("Could not perform seek on resource.");
218 case GST_RESOURCE_ERROR_SYNC:
219 return _("Could not synchronize on resource.");
220 case GST_RESOURCE_ERROR_SETTINGS:
221 return _("Could not get/set settings from/on resource.");
222 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
223 return _("No space left on the resource.");
224 case GST_RESOURCE_ERROR_NOT_AUTHORIZED:
225 return _("Not authorized to access resource.");
226 case GST_RESOURCE_ERROR_NUM_ERRORS:
234 gst_error_get_stream_error (GstStreamError code)
237 case GST_STREAM_ERROR_FAILED:
238 return _("GStreamer encountered a general stream error.");
239 case GST_STREAM_ERROR_TOO_LAZY:
240 return _("GStreamer developers were too lazy to assign an error code "
241 "to this error." FILE_A_BUG);
242 case GST_STREAM_ERROR_NOT_IMPLEMENTED:
243 return _("Element doesn't implement handling of this stream. "
244 "Please file a bug.");
245 case GST_STREAM_ERROR_TYPE_NOT_FOUND:
246 return _("Could not determine type of stream.");
247 case GST_STREAM_ERROR_WRONG_TYPE:
248 return _("The stream is of a different type than handled by this "
250 case GST_STREAM_ERROR_CODEC_NOT_FOUND:
251 return _("There is no codec present that can handle the stream's type.");
252 case GST_STREAM_ERROR_DECODE:
253 return _("Could not decode stream.");
254 case GST_STREAM_ERROR_ENCODE:
255 return _("Could not encode stream.");
256 case GST_STREAM_ERROR_DEMUX:
257 return _("Could not demultiplex stream.");
258 case GST_STREAM_ERROR_MUX:
259 return _("Could not multiplex stream.");
260 case GST_STREAM_ERROR_FORMAT:
261 return _("The stream is in the wrong format.");
262 case GST_STREAM_ERROR_DECRYPT:
263 return _("The stream is encrypted and decryption is not supported.");
264 case GST_STREAM_ERROR_DECRYPT_NOKEY:
265 return _("The stream is encrypted and can't be decrypted because no "
266 "suitable key has been supplied.");
267 case GST_STREAM_ERROR_NUM_ERRORS:
276 QUARK_FUNC (library);
277 QUARK_FUNC (resource);
281 * gst_error_get_message:
282 * @domain: the GStreamer error domain this error belongs to.
283 * @code: the error code belonging to the domain.
285 * Get a string describing the error message in the current locale.
287 * Returns: (transfer full): a newly allocated string describing
288 * the error message (in UTF-8 encoding)
291 gst_error_get_message (GQuark domain, gint code)
293 const gchar *message = NULL;
295 if (domain == GST_CORE_ERROR)
296 message = gst_error_get_core_error ((GstCoreError) code);
297 else if (domain == GST_LIBRARY_ERROR)
298 message = gst_error_get_library_error ((GstLibraryError) code);
299 else if (domain == GST_RESOURCE_ERROR)
300 message = gst_error_get_resource_error ((GstResourceError) code);
301 else if (domain == GST_STREAM_ERROR)
302 message = gst_error_get_stream_error ((GstStreamError) code);
304 g_warning ("No error messages for domain %s", g_quark_to_string (domain));
305 return g_strdup_printf (_("No error message for domain %s."),
306 g_quark_to_string (domain));
309 return g_strdup (message);
313 ("No standard error message for domain %s and code %d."),
314 g_quark_to_string (domain), code);