diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-07-17 13:28:26 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-07-17 13:28:26 +0300 |
commit | e952b9e1db69b1752d97c645740074b886927807 (patch) | |
tree | 0b40613f8ae7d1eb4274ae947231f54b07d1d834 /src/guile.c | |
parent | 98f611e8dd2c4210d2e05a01fb7d20250a082bc7 (diff) | |
download | idest-e952b9e1db69b1752d97c645740074b886927807.tar.gz idest-e952b9e1db69b1752d97c645740074b886927807.tar.bz2 |
Improve error reporting in Guile.
Diffstat (limited to 'src/guile.c')
-rw-r--r-- | src/guile.c | 87 |
1 files changed, 44 insertions, 43 deletions
diff --git a/src/guile.c b/src/guile.c index 5d10b99..4d3e517 100644 --- a/src/guile.c +++ b/src/guile.c @@ -126,6 +126,29 @@ guile_load(char *filename, int use_path, char **argv) &lc, NULL); } +static void +idest_guile_error(const char *subr, + const char *frame_id, + SCM field_id, + int errcode) +{ + if (field_id != SCM_BOOL_F) + scm_error(idest_error, subr, + "frame ~A, field ~A: ~A", + scm_list_3(scm_from_locale_string(frame_id), + field_id, + scm_from_locale_string(idest_strerror(errcode))), + scm_list_2(scm_from_int(errcode), field_id)); + else + scm_error(idest_error, subr, + "frame ~A: ~A (~A)", + scm_list_2(scm_from_locale_string(frame_id), + scm_from_locale_string(idest_strerror(errcode))), + scm_list_2(scm_from_int(errcode), + SCM_BOOL_F)); +} + + static SCM stringlist_to_scm(union id3_field *field, int genre) { @@ -232,15 +255,11 @@ frame_dump_to_scm(struct id3_frame *frame) SCM cell; char *s = field_to_string(field, 0); - if (!s) { - /* FIXME */ - scm_error(idest_error, "frame_dump_to_scm", - "frame ~A: ~A (~A)", - scm_list_3(scm_from_locale_string(frame->id), - scm_from_locale_string(idest_strerror(IDEST_ERR_BADFIELD)), - scm_from_int(IDEST_ERR_BADFIELD)), - SCM_BOOL_F); - } + if (!s) + idest_guile_error("frame_dump_to_scm", + frame->id, scm_from_int(i), + IDEST_ERR_BADFIELD); + cell = scm_cons(scm_list_3(scm_from_int(i), scm_from_int(field->type), scm_from_locale_string(s)), @@ -272,12 +291,8 @@ frame_to_scm(struct id3_frame *frame) rc = ft->decode(&itm, frame); if (rc) - scm_error(idest_error, "frame_to_scm", - "frame ~A: ~A (~A)", - scm_list_3(scm_from_locale_string(frame->id), - scm_from_locale_string(idest_strerror(rc)), - scm_from_int(rc)), - SCM_BOOL_F); + idest_guile_error("frame_to_scm", + frame->id, SCM_BOOL_F, rc); head = scm_cons(scm_cons(idest_text, scm_from_locale_string(itm.value)), @@ -345,12 +360,9 @@ ed_item_from_scm(struct ed_item *itm, SCM list) const struct idest_frametab *ft = idest_frame_lookup(itm->id); if (!ft) - scm_error(idest_error, "ed_item_from_scm", - "frame ~A: ~A (~A)", - scm_list_3(scm_from_locale_string(itm->id), - scm_from_locale_string(idest_strerror(IDEST_ERR_BADTYPE)), - scm_from_int(IDEST_ERR_BADTYPE)), - SCM_BOOL_F); + idest_guile_error("ed_item_from_scm", + itm->id, SCM_BOOL_F, + IDEST_ERR_BADTYPE); itm->qc = ft->qc; itm->qv = xcalloc(itm->qc, sizeof(itm->qv[0])); for (; !scm_is_null(list) && scm_is_pair(list); list = SCM_CDR(list)) { @@ -368,15 +380,11 @@ ed_item_from_scm(struct ed_item *itm, SCM list) continue; s = scm_to_locale_string(scm_symbol_to_string(key)); n = qvname_to_ind(ft, s); - if (n == -1) { - /* FIXME: field name? */ - scm_error(idest_error, "ed_item_from_scm", - "frame ~A: ~A (~A)", - scm_list_3(scm_from_locale_string(itm->id), - scm_from_locale_string(idest_strerror(IDEST_ERR_BADFIELD)), - scm_from_int(IDEST_ERR_BADFIELD)), - SCM_BOOL_F); - } + if (n == -1) + idest_guile_error("ed_item_from_scm", + itm->id, key, + IDEST_ERR_BADFIELD); + free(s); itm->qv[n] = scm_to_locale_string(SCM_CDR(elt)); } @@ -433,13 +441,10 @@ scm_to_tag(SCM scm, struct id3_tag *tag) id = scm_to_locale_string(x); frametype = id3_frametype_lookup(id, strlen(id)); - if (!id) - scm_error(idest_error, "guile-transform", - "frame ~A: ~A (~A)", - scm_list_3(x, - scm_from_locale_string(idest_strerror(IDEST_ERR_BADTYPE)), - scm_from_int(IDEST_ERR_BADTYPE)), - SCM_BOOL_F); + if (!frametype) + idest_guile_error("guile-transform", + id, SCM_BOOL_F, + IDEST_ERR_BADTYPE); ed_item_zero(&itm); memcpy(itm.id, id, sizeof(itm.id)); @@ -472,12 +477,8 @@ scm_to_tag(SCM scm, struct id3_tag *tag) else rc = set_frame_value(frame, &itm); if (rc) - scm_error(idest_error, "guile-transform", - "frame ~A: ~A (~A)", - scm_list_3(scm_from_locale_string(frame->id), - scm_from_locale_string(idest_strerror(rc)), - scm_from_int(rc)), - SCM_BOOL_F); + idest_guile_error("guile-transform", + frame->id, SCM_BOOL_F, rc); modified |= 1; free(id); |