app: simplify GimpData load/save error reporting a lot

Add the filename and general "Foo failed" spam generically in GimpData
and GimpDataFactory, and make the individual loaders/savers much
simpler.
This commit is contained in:
Michael Natterer 2014-07-04 18:46:02 +02:00
parent 29427fa4f1
commit e6f4252d55
12 changed files with 123 additions and 242 deletions

View File

@ -96,7 +96,6 @@ static gint32 abr_read_long (GDataInputStream *input,
static gchar * abr_read_ucs2_text (GDataInputStream *input,
GError **error);
static gboolean abr_supported (AbrHeader *abr_hdr,
GFile *f,
GError **error);
static gboolean abr_reach_8bim_section (GDataInputStream *input,
const gchar *name,
@ -142,7 +141,6 @@ gimp_brush_load_brush (GimpContext *context,
guchar *mask;
gsize bytes_read;
gssize i, size;
GError *my_error = NULL;
gboolean success = TRUE;
g_return_val_if_fail (G_IS_FILE (file), NULL);
@ -151,16 +149,9 @@ gimp_brush_load_brush (GimpContext *context,
/* read the header */
if (! g_input_stream_read_all (input, &header, sizeof (header),
&bytes_read, NULL, &my_error) ||
&bytes_read, NULL, error) ||
bytes_read != sizeof (header))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
ngettext ("Could not read %d byte from '%s': %s",
"Could not read %d bytes from '%s': %s",
(gint) sizeof (header)),
(gint) sizeof (header),
gimp_file_get_utf8_name (file), my_error->message);
g_clear_error (&my_error);
return NULL;
}
@ -178,27 +169,21 @@ gimp_brush_load_brush (GimpContext *context,
if (header.width == 0)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Width = 0."),
gimp_file_get_utf8_name (file));
_("Fatal parse error in brush file: Width = 0."));
return NULL;
}
if (header.height == 0)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Height = 0."),
gimp_file_get_utf8_name (file));
_("Fatal parse error in brush file: Height = 0."));
return NULL;
}
if (header.bytes == 0)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Bytes = 0."),
gimp_file_get_utf8_name (file));
_("Fatal parse error in brush file: Bytes = 0."));
return NULL;
}
@ -223,9 +208,8 @@ gimp_brush_load_brush (GimpContext *context,
else
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Unknown depth %d."),
gimp_file_get_utf8_name (file), header.bytes);
_("Fatal parse error in brush file: Unknown depth %d."),
header.bytes);
return NULL;
}
/* fallthrough */
@ -236,9 +220,8 @@ gimp_brush_load_brush (GimpContext *context,
default:
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Unknown version %d."),
gimp_file_get_utf8_name (file), header.version);
_("Fatal parse error in brush file: Unknown version %d."),
header.version);
return NULL;
}
@ -250,13 +233,9 @@ gimp_brush_load_brush (GimpContext *context,
name = g_new (gchar, bn_size);
if (! g_input_stream_read_all (input, name, bn_size,
&bytes_read, NULL, NULL) ||
&bytes_read, NULL, error) ||
bytes_read != bn_size)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"File appears truncated."),
gimp_file_get_utf8_name (file));
g_free (name);
return NULL;
}
@ -287,7 +266,7 @@ gimp_brush_load_brush (GimpContext *context,
{
case 1:
success = (g_input_stream_read_all (input, mask, size,
&bytes_read, NULL, NULL) &&
&bytes_read, NULL, error) &&
bytes_read == size);
break;
@ -300,7 +279,7 @@ gimp_brush_load_brush (GimpContext *context,
gssize bytes = MIN (size - i, sizeof (buf));
success = (g_input_stream_read_all (input, buf, bytes,
&bytes_read, NULL, NULL) &&
&bytes_read, NULL, error) &&
bytes_read == bytes);
if (success)
@ -340,12 +319,12 @@ gimp_brush_load_brush (GimpContext *context,
*/
g_object_unref (brush);
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
_("Fatal parse error in brush file:\n"
"Unsupported brush depth %d\n"
"GIMP brushes must be GRAY or RGBA.\n"
"This might be an obsolete GIMP brush file, try "
"loading it as image and save it again."),
gimp_file_get_utf8_name (file), header.bytes);
header.bytes);
return NULL;
break;
@ -362,7 +341,7 @@ gimp_brush_load_brush (GimpContext *context,
gssize bytes = MIN (size - i, sizeof (buf));
success = (g_input_stream_read_all (input, buf, bytes,
&bytes_read, NULL, NULL) &&
&bytes_read, NULL, error) &&
bytes_read == bytes);
if (success)
@ -387,20 +366,16 @@ gimp_brush_load_brush (GimpContext *context,
default:
g_object_unref (brush);
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
_("Fatal parse error in brush file:\n"
"Unsupported brush depth %d\n"
"GIMP brushes must be GRAY or RGBA."),
gimp_file_get_utf8_name (file), header.bytes);
header.bytes);
return NULL;
}
if (! success)
{
g_object_unref (brush);
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"File appears truncated."),
gimp_file_get_utf8_name (file));
return NULL;
}
@ -442,7 +417,7 @@ gimp_brush_load_abr (GimpContext *context,
if (my_error)
goto done;
if (abr_supported (&abr_hdr, file, &my_error))
if (abr_supported (&abr_hdr, &my_error))
{
switch (abr_hdr.version)
{
@ -469,13 +444,9 @@ gimp_brush_load_abr (GimpContext *context,
g_set_error (&my_error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Unable to decode abr format version %d."),
abr_hdr.version);
g_set_error (error, my_error->domain, my_error->code,
_("Fatal parse error in brush file '%s': %s"),
gimp_file_get_utf8_name (file), my_error->message);
}
g_clear_error (&my_error);
g_propagate_error (error, my_error);
return g_list_reverse (brush_list);
}
@ -668,9 +639,8 @@ gimp_brush_load_abr_brush_v12 (GDataInputStream *input,
/* FIXME: support wide brushes */
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Wide brushes are not supported."),
gimp_file_get_utf8_name (file));
_("Fatal parse error in brush file: "
"Wide brushes are not supported."));
break;
}
@ -810,9 +780,8 @@ gimp_brush_load_abr_brush_v6 (GDataInputStream *input,
if (! r)
{
g_prefix_error (error,
_("Fatal parse error in brush file '%s': "
"File appears truncated: "),
gimp_file_get_utf8_name (file));
_("Fatal parse error in brush file : "
"File appears truncated: "));
return NULL;
}
@ -942,7 +911,6 @@ abr_read_ucs2_text (GDataInputStream *input,
static gboolean
abr_supported (AbrHeader *abr_hdr,
GFile *file,
GError **error)
{
switch (abr_hdr->version)
@ -958,9 +926,8 @@ abr_supported (AbrHeader *abr_hdr,
return TRUE;
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"unable to decode abr format version %d."),
gimp_file_get_utf8_name (file),
_("Fatal parse error in brush file: "
"Unable to decode abr format version %d."),
/* horrid subversion display, but better than
* having yet another translatable string for

View File

@ -54,7 +54,6 @@ gimp_brush_generated_load (GimpContext *context,
gdouble hardness;
gdouble aspect_ratio;
gdouble angle;
GError *my_error = NULL;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
@ -66,16 +65,14 @@ gimp_brush_generated_load (GimpContext *context,
linenum = 1;
string_len = 256;
string = g_data_input_stream_read_line (data_input, &string_len,
NULL, &my_error);
NULL, error);
if (! string)
goto failed;
if (! g_str_has_prefix (string, "GIMP-VBR"))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Not a GIMP brush file."),
gimp_file_get_utf8_name (file));
_("Not a GIMP brush file."));
g_free (string);
goto failed;
}
@ -86,7 +83,7 @@ gimp_brush_generated_load (GimpContext *context,
linenum++;
string_len = 256;
string = g_data_input_stream_read_line (data_input, &string_len,
NULL, &my_error);
NULL, error);
if (! string)
goto failed;
@ -95,9 +92,7 @@ gimp_brush_generated_load (GimpContext *context,
if (! g_str_has_prefix (string, "1.5"))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Unknown GIMP brush version in line %d."),
gimp_file_get_utf8_name (file), linenum);
_("Unknown GIMP brush version."));
g_free (string);
goto failed;
}
@ -113,7 +108,7 @@ gimp_brush_generated_load (GimpContext *context,
linenum++;
string_len = 256;
string = g_data_input_stream_read_line (data_input, &string_len,
NULL, &my_error);
NULL, error);
if (! string)
goto failed;
@ -140,7 +135,7 @@ gimp_brush_generated_load (GimpContext *context,
linenum++;
string_len = 256;
string = g_data_input_stream_read_line (data_input, &string_len,
NULL, &my_error);
NULL, error);
if (! string)
goto failed;
@ -150,9 +145,7 @@ gimp_brush_generated_load (GimpContext *context,
if (! shape_val)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Unknown GIMP brush shape in line %d."),
gimp_file_get_utf8_name (file), linenum);
_("Unknown GIMP brush shape."));
g_free (string);
goto failed;
}
@ -166,7 +159,7 @@ gimp_brush_generated_load (GimpContext *context,
linenum++;
string_len = 256;
string = g_data_input_stream_read_line (data_input, &string_len,
NULL, &my_error);
NULL, error);
if (! string)
goto failed;
spacing = g_ascii_strtod (string, NULL);
@ -176,7 +169,7 @@ gimp_brush_generated_load (GimpContext *context,
linenum++;
string_len = 256;
string = g_data_input_stream_read_line (data_input, &string_len,
NULL, &my_error);
NULL, error);
if (! string)
goto failed;
radius = g_ascii_strtod (string, NULL);
@ -188,7 +181,7 @@ gimp_brush_generated_load (GimpContext *context,
linenum++;
string_len = 256;
string = g_data_input_stream_read_line (data_input, &string_len,
NULL, &my_error);
NULL, error);
if (! string)
goto failed;
spikes = CLAMP (atoi (string), 2, 20);
@ -199,7 +192,7 @@ gimp_brush_generated_load (GimpContext *context,
linenum++;
string_len = 256;
string = g_data_input_stream_read_line (data_input, &string_len,
NULL, &my_error);
NULL, error);
if (! string)
goto failed;
hardness = g_ascii_strtod (string, NULL);
@ -209,7 +202,7 @@ gimp_brush_generated_load (GimpContext *context,
linenum++;
string_len = 256;
string = g_data_input_stream_read_line (data_input, &string_len,
NULL, &my_error);
NULL, error);
if (! string)
goto failed;
aspect_ratio = g_ascii_strtod (string, NULL);
@ -219,7 +212,7 @@ gimp_brush_generated_load (GimpContext *context,
linenum++;
string_len = 256;
string = g_data_input_stream_read_line (data_input, &string_len,
NULL, &my_error);
NULL, error);
if (! string)
goto failed;
angle = g_ascii_strtod (string, NULL);
@ -242,23 +235,7 @@ gimp_brush_generated_load (GimpContext *context,
if (name)
g_free (name);
if (error && *error == NULL)
{
gchar *msg;
if (my_error)
msg = g_strdup_printf (_("Line %d: %s"), linenum, my_error->message);
else
msg = g_strdup_printf (_("File is truncated in line %d"), linenum);
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Error while reading brush file '%s': %s"),
gimp_file_get_utf8_name (file), msg);
g_free (msg);
}
g_clear_error (&my_error);
g_prefix_error (error, _("In line %d of brush file: "), linenum);
return NULL;
}

View File

@ -43,7 +43,6 @@ gimp_brush_generated_save (GimpData *data,
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
gsize bytes_written;
gboolean have_shape = FALSE;
GError *my_error = NULL;
g_return_val_if_fail (name != NULL && *name != '\0', FALSE);
@ -108,15 +107,11 @@ gimp_brush_generated_save (GimpData *data,
brush->angle));
if (! g_output_stream_write_all (output, string->str, string->len,
&bytes_written, NULL, &my_error) ||
&bytes_written, NULL, error) ||
bytes_written != string->len)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_WRITE,
_("Writing brush file '%s' failed: %s"),
gimp_file_get_utf8_name (gimp_data_get_file (data)),
my_error->message);
g_clear_error (&my_error);
g_string_free (string, TRUE);
return FALSE;
}

View File

@ -190,11 +190,9 @@ gimp_brush_pipe_load (GimpContext *context,
while (pipe->n_brushes < num_of_brushes)
{
GError *my_error = NULL;
pipe->brushes[pipe->n_brushes] = gimp_brush_load_brush (context,
file, input,
&my_error);
error);
if (pipe->brushes[pipe->n_brushes])
{
@ -203,7 +201,6 @@ gimp_brush_pipe_load (GimpContext *context,
}
else
{
g_propagate_error (error, my_error);
g_object_unref (pipe);
return NULL;
}

View File

@ -529,15 +529,28 @@ gimp_data_save (GimpData *data,
{
success = GIMP_DATA_GET_CLASS (data)->save (data, output, error);
if (success &&
! g_output_stream_close (output, NULL, error))
if (success)
{
if (! g_output_stream_close (output, NULL, error))
{
g_prefix_error (error,
_("Error writing '%s': "),
_("Error saving '%s': "),
gimp_file_get_utf8_name (private->file));
success = FALSE;
}
}
else if (error && *error)
{
g_prefix_error (error,
_("Error saving '%s': "),
gimp_file_get_utf8_name (private->file));
}
else
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_WRITE,
_("Error saving '%s'"),
gimp_file_get_utf8_name (private->file));
}
g_object_unref (output);
}

View File

@ -894,6 +894,19 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data,
{
data_list = loader->load_func (context->context, file, input, &error);
if (error)
{
g_prefix_error (&error,
_("Error loading '%s': "),
gimp_file_get_utf8_name (file));
}
else if (! data_list)
{
g_set_error (&error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Error loading '%s'"),
gimp_file_get_utf8_name (file));
}
g_object_unref (input);
}
else

View File

@ -52,7 +52,6 @@ gimp_gradient_load (GimpContext *context,
gchar *line;
gsize line_len;
gint linenum;
GError *my_error = NULL;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
@ -63,13 +62,13 @@ gimp_gradient_load (GimpContext *context,
linenum = 1;
line_len = 1024;
line = g_data_input_stream_read_line (data_input, &line_len,
NULL, &my_error);
NULL, error);
if (! line)
goto failed;
if (! g_str_has_prefix (line, "GIMP Gradient"))
{
g_set_error (&my_error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Not a GIMP gradient file."));
g_free (line);
goto failed;
@ -84,7 +83,7 @@ gimp_gradient_load (GimpContext *context,
linenum++;
line_len = 1024;
line = g_data_input_stream_read_line (data_input, &line_len,
NULL, &my_error);
NULL, error);
if (! line)
goto failed;
@ -102,7 +101,7 @@ gimp_gradient_load (GimpContext *context,
linenum++;
line_len = 1024;
line = g_data_input_stream_read_line (data_input, &line_len,
NULL, &my_error);
NULL, error);
if (! line)
goto failed;
}
@ -118,7 +117,7 @@ gimp_gradient_load (GimpContext *context,
if (num_segments < 1)
{
g_set_error (&my_error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("File is corrupt."));
goto failed;
}
@ -142,7 +141,7 @@ gimp_gradient_load (GimpContext *context,
linenum++;
line_len = 1024;
line = g_data_input_stream_read_line (data_input, &line_len,
NULL, &my_error);
NULL, error);
if (! line)
goto failed;
@ -192,14 +191,14 @@ gimp_gradient_load (GimpContext *context,
break;
default:
g_set_error (&my_error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Corrupt segment %d."), i);
goto failed;
}
}
else
{
g_set_error (&my_error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Corrupt segment %d."), i);
goto failed;
}
@ -207,7 +206,7 @@ gimp_gradient_load (GimpContext *context,
if (( prev && (prev->right < seg->left)) ||
(! prev && (0.0 < seg->left)))
{
g_set_error (&my_error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Segments do not span the range 0-1."));
goto failed;
}
@ -217,7 +216,7 @@ gimp_gradient_load (GimpContext *context,
if (prev->right < 1.0)
{
g_set_error (&my_error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Segments do not span the range 0-1."));
goto failed;
}
@ -233,24 +232,7 @@ gimp_gradient_load (GimpContext *context,
if (gradient)
g_object_unref (gradient);
if (error && *error == NULL)
{
gchar *msg;
if (my_error)
msg = g_strdup_printf (_("Error in line %d: %s"), linenum,
my_error->message);
else
msg = g_strdup_printf (_("File is truncated in line %d"), linenum);
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Error while reading gradient file '%s': %s"),
gimp_file_get_utf8_name (file), msg);
g_free (msg);
}
g_clear_error (&my_error);
g_prefix_error (error, _("In line %d of gradient file: "), linenum);
return NULL;
}
@ -326,21 +308,7 @@ gimp_gradient_load_svg (GimpContext *context,
if (success && ! parser.gradients)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("No linear gradients found in '%s'"),
gimp_file_get_utf8_name (file));
}
else
{
if (error && *error) /* parser reported an error */
{
gchar *msg = (*error)->message;
(*error)->message =
g_strdup_printf (_("Failed to import gradients from '%s': %s"),
gimp_file_get_utf8_name (file), msg);
g_free (msg);
}
_("No linear gradients found."));
}
if (parser.gradient)

View File

@ -40,7 +40,6 @@ gimp_gradient_save (GimpData *data,
GimpGradientSegment *seg;
gint num_segments;
gsize bytes_written;
GError *my_error = NULL;
/* File format is:
*
@ -109,15 +108,11 @@ gimp_gradient_save (GimpData *data,
}
if (! g_output_stream_write_all (output, string->str, string->len,
&bytes_written, NULL, &my_error) ||
&bytes_written, NULL, error) ||
bytes_written != string->len)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_WRITE,
_("Writing gradient file '%s' failed: %s"),
gimp_file_get_utf8_name (gimp_data_get_file (data)),
my_error->message);
g_clear_error (&my_error);
g_string_free (string, TRUE);
return FALSE;
}

View File

@ -48,7 +48,6 @@ gimp_palette_load (GimpContext *context,
gchar *tok;
gint r, g, b;
gint linenum;
GError *my_error = NULL;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
@ -61,13 +60,13 @@ gimp_palette_load (GimpContext *context,
linenum = 1;
str_len = 1024;
str = g_data_input_stream_read_line (data_input, &str_len,
NULL, &my_error);
NULL, error);
if (! str)
goto failed;
if (! g_str_has_prefix (str, "GIMP Palette"))
{
g_set_error (&my_error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Missing magic header."));
g_free (str);
goto failed;
@ -80,7 +79,7 @@ gimp_palette_load (GimpContext *context,
linenum++;
str_len = 1024;
str = g_data_input_stream_read_line (data_input, &str_len,
NULL, &my_error);
NULL, error);
if (! str)
goto failed;
@ -97,7 +96,7 @@ gimp_palette_load (GimpContext *context,
linenum++;
str_len = 1024;
str = g_data_input_stream_read_line (data_input, &str_len,
NULL, &my_error);
NULL, error);
if (! str)
goto failed;
@ -122,7 +121,7 @@ gimp_palette_load (GimpContext *context,
linenum++;
str_len = 1024;
str = g_data_input_stream_read_line (data_input, &str_len,
NULL, &my_error);
NULL, error);
if (! str)
goto failed;
}
@ -135,6 +134,8 @@ gimp_palette_load (GimpContext *context,
while (str)
{
GError *my_error = NULL;
if (str[0] != '#' && str[0] != '\n')
{
tok = strtok (str, " \t");
@ -196,7 +197,10 @@ gimp_palette_load (GimpContext *context,
if (! str)
{
if (! palette->colors)
{
g_propagate_error (error, my_error);
goto failed;
}
if (my_error)
{
@ -224,24 +228,7 @@ gimp_palette_load (GimpContext *context,
if (palette)
g_object_unref (palette);
if (error && *error == NULL)
{
gchar *msg;
if (my_error)
msg = g_strdup_printf (_("Error in line %d: %s"), linenum,
my_error->message);
else
msg = g_strdup_printf (_("File is truncated in line %d"), linenum);
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Error while reading palette file '%s': %s"),
gimp_file_get_utf8_name (file), msg);
g_free (msg);
}
g_clear_error (&my_error);
g_prefix_error (error, _("In line %d of palette file: "), linenum);
return NULL;
}
@ -436,8 +423,9 @@ gimp_palette_load_aco (GimpContext *context,
&bytes_read, NULL, error) ||
bytes_read != sizeof (header))
{
g_prefix_error (error, "%s",
_("Could not read header from palette file '%s': "));
g_prefix_error (error,
_("Could not read header from palette file '%s': "),
gimp_file_get_utf8_name (file));
return NULL;
}
@ -473,21 +461,7 @@ gimp_palette_load_aco (GimpContext *context,
break;
}
if (error && *error == NULL)
{
const gchar *msg;
if (my_error)
msg = my_error->message;
else
msg = _("File is truncated.");
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': %s"),
gimp_file_get_utf8_name (file), msg);
}
g_clear_error (&my_error);
g_propagate_error (error, my_error);
g_object_unref (palette);
return NULL;
@ -573,14 +547,9 @@ gimp_palette_load_aco (GimpContext *context,
if (! g_input_stream_read_all (input,
format2_preamble,
sizeof (format2_preamble),
&bytes_read, NULL, &my_error) ||
&bytes_read, NULL, error) ||
bytes_read != sizeof (format2_preamble))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': %s"),
gimp_file_get_utf8_name (file),
my_error ?
my_error->message : _("Premature end of file."));
g_object_unref (palette);
return NULL;
}

View File

@ -41,13 +41,13 @@ gimp_palette_save (GimpData *data,
GString *string;
GList *list;
gsize bytes_written;
GError *my_error = NULL;
string = g_string_new ("GIMP Palette\n");
g_string_append_printf (string,
"Name: %s\n"
"Columns: %d\n#\n",
"Columns: %d\n"
"#\n",
gimp_object_get_name (palette),
CLAMP (gimp_palette_get_columns (palette), 0, 256));
@ -65,15 +65,11 @@ gimp_palette_save (GimpData *data,
}
if (! g_output_stream_write_all (output, string->str, string->len,
&bytes_written, NULL, &my_error) ||
&bytes_written, NULL, error) ||
bytes_written != string->len)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_WRITE,
_("Writing palette file '%s' failed: %s"),
gimp_file_get_utf8_name (gimp_data_get_file (data)),
my_error->message);
g_clear_error (&my_error);
g_string_free (string, TRUE);
return FALSE;
}

View File

@ -54,13 +54,10 @@ gimp_pattern_load (GimpContext *context,
/* read the size */
if (! g_input_stream_read_all (input, &header, sizeof (header),
&bytes_read, NULL, NULL) ||
&bytes_read, NULL, error) ||
bytes_read != sizeof (header))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in pattern file '%s': "
"File appears truncated."),
gimp_file_get_utf8_name (file));
g_prefix_error (error, _("File appears truncated: "));
goto error;
}
@ -77,9 +74,8 @@ gimp_pattern_load (GimpContext *context,
header.header_size <= sizeof (header))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in pattern file '%s': "
"Unknown pattern format version %d."),
gimp_file_get_utf8_name (file), header.version);
_("Unknown pattern format version %d."),
header.version);
goto error;
}
@ -87,10 +83,9 @@ gimp_pattern_load (GimpContext *context,
if (header.bytes < 1 || header.bytes > 4)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in pattern file '%s: "
"Unsupported pattern depth %d.\n"
_("Unsupported pattern depth %d.\n"
"GIMP Patterns must be GRAY or RGB."),
gimp_file_get_utf8_name (file), header.bytes);
header.bytes);
goto error;
}
@ -102,13 +97,10 @@ gimp_pattern_load (GimpContext *context,
name = g_new (gchar, bn_size);
if (! g_input_stream_read_all (input, name, bn_size,
&bytes_read, NULL, NULL) ||
&bytes_read, NULL, error) ||
bytes_read != bn_size)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in pattern file '%s': "
"File appears truncated."),
gimp_file_get_utf8_name (file));
g_prefix_error (error, _("File appears truncated."));
g_free (name);
goto error;
}
@ -143,13 +135,10 @@ gimp_pattern_load (GimpContext *context,
if (! g_input_stream_read_all (input,
gimp_temp_buf_get_data (pattern->mask), size,
&bytes_read, NULL, NULL) ||
&bytes_read, NULL, error) ||
bytes_read != size)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in pattern file '%s': "
"File appears truncated."),
gimp_file_get_utf8_name (file));
g_prefix_error (error, _("File appears truncated."));
goto error;
}
@ -160,6 +149,8 @@ gimp_pattern_load (GimpContext *context,
if (pattern)
g_object_unref (pattern);
g_prefix_error (error, _("Fatal parse error in pattern file: "));
return NULL;
}

View File

@ -59,9 +59,9 @@ gimp_tool_preset_load (GimpContext *context,
}
else
{
g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,
_("Error while parsing '%s'"),
gimp_file_get_utf8_name (file));
g_set_error_literal (error,
GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,
_("Tool preset file is corrupt."));
}
}