Error messages and error handling [src]
Error messages and error handling
libvips maintains an error buffer (a log of localised text messages), a set of functions for adding messages, and a way to access and clear the buffer.
The error buffer is global, that is, it is shared between all threads. You can add to the buffer from any thread (there is a lock to prevent corruption), but it’s sensible to only read and clear the buffer from the main thread of execution.
The general principle is: if you detect an error, log a message for the user. If a function you call detects an error, just propagate it and don’t add another message.
VipsImage *im;
if (!(im = vips_image_new_from_file(filename, NULL)))
// vips_image_new_from_file() will set a message, we don't need to
return -1;
if (vips_image_get_width(im) < 100) {
// we have detected an error, we must set a message
vips_error("myprogram", "%s", _("width too small"));
return -1;
}
The domain argument most of these functions take is not localised and is supposed to indicate the component which failed.
libvips uses g_warning()
and g_info()
to send warning and
information messages to the user. You can use the usual GLib mechanisms to
display or divert these messages. For example, info messages are hidden by
default, but you can see them with:
$ G_MESSAGES_DEBUG=VIPS vipsthumbnail k2.jpg
VIPS-INFO: thumbnailing k2.jpg
VIPS-INFO: selected loader is VipsForeignLoadJpegFile
VIPS-INFO: input size is 1450 x 2048
VIPS-INFO: loading jpeg with factor 8 pre-shrink
VIPS-INFO: converting to processing space srgb
VIPS-INFO: residual reducev by 0.5
VIPS-INFO: 13 point mask
VIPS-INFO: using vector path
VIPS-INFO: residual reduceh by 0.5
VIPS-INFO: 13 point mask
VIPS-INFO: thumbnailing k2.jpg as ./tn_k2.jpg
Functions
vips_error_buffer()
vips_error_buffer_copy()
vips_error_clear()
vips_error_freeze()
vips_error_thaw()
vips_error()
vips_verror()
vips_error_system()
vips_verror_system()
vips_error_g()
vips_g_error()
vips_error_exit()
vips_check_uncoded()
vips_check_coding()
vips_check_coding_known()
vips_check_coding_noneorlabq()
vips_check_coding_same()
vips_check_mono()
vips_check_bands()
vips_check_bands_1or3()
vips_check_bands_atleast()
vips_check_bands_1orn()
vips_check_bands_1orn_unary()
vips_check_bands_same()
vips_check_bandno()
vips_check_int()
vips_check_uint()
vips_check_uintorf()
vips_check_noncomplex()
vips_check_complex()
vips_check_twocomponents()
vips_check_format()
vips_check_u8or16()
vips_check_8or16()
vips_check_u8or16orf()
vips_check_format_same()
vips_check_size_same()
vips_check_oddsquare()
vips_check_vector_length()
vips_check_vector()
vips_check_hist()
vips_check_matrix()
vips_check_separable()
vips_check_precision_intfloat()