libvips maintains an error buffer (a log of localised text messages), a setof 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. Youcan add to the buffer from any thread (there is a lock to preventcorruption), but it’s sensible to only read and clear the buffer from themain thread of execution.
The general principle is: if you detect an error, log a message for theuser. If a function you call detects an error, just propagate it and don’tadd 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 toreturn-1;if(vips_image_get_width(im)<100){// we have detected an error, we must set a messagevips_error("myprogram","%s",_("width too small"));return-1;}
The domain argument most of these functions take is not localised and issupposed to indicate the component which failed.
libvips usesg_warning()
andg_info()
to send warning andinformation messages to the user. You can use the usual GLib mechanisms todisplay or divert these messages. For example, info messages are hidden bydefault, but you can see them with:
$G_MESSAGES_DEBUG=VIPSvipsthumbnailk2.jpgVIPS-INFO:thumbnailingk2.jpgVIPS-INFO:selectedloaderisVipsForeignLoadJpegFileVIPS-INFO:inputsizeis1450x2048VIPS-INFO:loadingjpegwithfactor8pre-shrinkVIPS-INFO:convertingtoprocessingspacesrgbVIPS-INFO:residualreducevby0.5VIPS-INFO:13pointmaskVIPS-INFO:usingvectorpathVIPS-INFO:residualreducehby0.5VIPS-INFO:13pointmaskVIPS-INFO:thumbnailingk2.jpgas./tn_k2.jpg
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()