better error reporting for edje_cc.

Instead of saying lots of possibilities that confuse users, check the
correct one and possibly give a hint.



SVN revision: 44669
This commit is contained in:
Gustavo Sverzut Barbieri 2009-12-22 23:56:11 +00:00
parent 51c00c6526
commit a85cc11943
2 changed files with 98 additions and 17 deletions

View File

@ -18,7 +18,7 @@ mem_alloc(size_t size)
mem = calloc(1, size); mem = calloc(1, size);
if (mem) return mem; if (mem) return mem;
ERR("%s: Error. %s:%i memory allocation of %i bytes failed. %s", ERR("%s: Error. %s:%i memory allocation of %zi bytes failed. %s",
progname, file_in, line, size, strerror(errno)); progname, file_in, line, size, strerror(errno));
exit(-1); exit(-1);
return NULL; return NULL;
@ -31,7 +31,7 @@ mem_strdup(const char *s)
str = strdup(s); str = strdup(s);
if (str) return str; if (str) return str;
ERR("%s: Error. %s:%i memory allocation of %i bytes failed. %s. string being duplicated: \"%s\"", ERR("%s: Error. %s:%i memory allocation of %zi bytes failed. %s. string being duplicated: \"%s\"",
progname, file_in, line, strlen(s) + 1, strerror(errno), s); progname, file_in, line, strlen(s) + 1, strerror(errno), s);
exit(-1); exit(-1);
return NULL; return NULL;

View File

@ -133,7 +133,7 @@ error_and_abort(Eet_File *ef, const char *fmt, ...)
{ {
va_list ap; va_list ap;
ERR("%s: Error. ", progname); fprintf(stderr, "%s: Error. ", progname);
va_start(ap, fmt); va_start(ap, fmt);
vfprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);
@ -382,6 +382,88 @@ data_write_fonts(Eet_File *ef, int *font_num, int *input_bytes, int *input_raw_b
return total_bytes; return total_bytes;
} }
static void
error_and_abort_image_load_error(Eet_File *ef, const char *file, int error)
{
const char *errmsg = evas_load_error_str(error);
char hint[1024] = "";
if (error == EVAS_LOAD_ERROR_DOES_NOT_EXIST)
{
snprintf
(hint, sizeof(hint),
" Check if path to file \"%s\" is correct "
"(both directory and file name).",
file);
}
else if (error == EVAS_LOAD_ERROR_CORRUPT_FILE)
{
snprintf
(hint, sizeof(hint),
" Check if file \"%s\" is consistent.",
file);
}
else if (error == EVAS_LOAD_ERROR_UNKNOWN_FORMAT)
{
const char *ext = strrchr(file, '.');
const char **itr, *known_loaders[] = {
/* list from evas_image_load.c */
"png",
"jpg",
"jpeg",
"jfif",
"eet",
"edj",
"eap",
"edb",
"xpm",
"tiff",
"tif",
"svg",
"svgz",
"gif",
"pbm",
"pgm",
"ppm",
"pnm",
NULL
};
if (!ext)
{
snprintf
(hint, sizeof(hint),
" File \"%s\" does not have an extension, "
"maybe it should?",
file);
goto show_err;
}
ext++;
for (itr = known_loaders; *itr; itr++)
{
if (strcasecmp(ext, *itr) == 0)
{
snprintf
(hint, sizeof(hint),
" Check if Evas was compiled with %s module enabled and "
"all required dependencies exist.",
ext);
goto show_err;
}
}
snprintf(hint, sizeof(hint),
" Check if Evas supports loading files of type \"%s\" (%s) "
"and this module was compiled and all its dependencies exist.",
ext, file);
}
show_err:
error_and_abort
(ef, "Unable to load image \"%s\" used by file \"%s\": %s.%s\n",
file, file_out, errmsg, hint);
}
static int static int
data_write_images(Eet_File *ef, int *image_num, int *input_bytes, int *input_raw_bytes) data_write_images(Eet_File *ef, int *image_num, int *input_bytes, int *input_raw_bytes)
{ {
@ -414,6 +496,7 @@ data_write_images(Eet_File *ef, int *image_num, int *input_bytes, int *input_raw
Evas_Object *im; Evas_Object *im;
Eina_List *ll; Eina_List *ll;
char *data; char *data;
int load_err = EVAS_LOAD_ERROR_NONE;
im = NULL; im = NULL;
EINA_LIST_FOREACH(img_dirs, ll, data) EINA_LIST_FOREACH(img_dirs, ll, data)
@ -426,23 +509,23 @@ data_write_images(Eet_File *ef, int *image_num, int *input_bytes, int *input_raw
if (im) if (im)
{ {
evas_object_image_file_set(im, buf, NULL); evas_object_image_file_set(im, buf, NULL);
if (evas_object_image_load_error_get(im) == load_err = evas_object_image_load_error_get(im);
EVAS_LOAD_ERROR_NONE) if (load_err == EVAS_LOAD_ERROR_NONE)
{ break;
break;
}
evas_object_del(im); evas_object_del(im);
im = NULL; im = NULL;
if (load_err != EVAS_LOAD_ERROR_DOES_NOT_EXIST)
break;
} }
} }
if (!im) if ((!im) && (load_err == EVAS_LOAD_ERROR_DOES_NOT_EXIST))
{ {
im = evas_object_image_add(evas); im = evas_object_image_add(evas);
if (im) if (im)
{ {
evas_object_image_file_set(im, img->entry, NULL); evas_object_image_file_set(im, img->entry, NULL);
if (evas_object_image_load_error_get(im) != load_err = evas_object_image_load_error_get(im);
EVAS_LOAD_ERROR_NONE) if (load_err != EVAS_LOAD_ERROR_NONE)
{ {
evas_object_del(im); evas_object_del(im);
im = NULL; im = NULL;
@ -521,10 +604,8 @@ data_write_images(Eet_File *ef, int *image_num, int *input_bytes, int *input_raw
} }
else else
{ {
error_and_abort(ef, "Unable to load image for " error_and_abort_image_load_error
"image part \"%s\" as \"%s\" part " (ef, img->entry, load_err);
"entry to %s\n", img->entry, buf,
file_out);
} }
if (verbose) if (verbose)
@ -547,8 +628,8 @@ data_write_images(Eet_File *ef, int *image_num, int *input_bytes, int *input_raw
} }
else else
{ {
error_and_abort(ef, "Unable to load image for image \"%s\" part entry to %s. Missing PNG or JPEG loader modules for Evas or file does not exist, or is not readable.\n", error_and_abort_image_load_error
img->entry, file_out); (ef, img->entry, load_err);
} }
} }
} }