From 516f479a1ddb3bb783a01e9ffb20ba051243ffd0 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Wed, 15 Jun 2011 15:38:27 +0300 Subject: Improve error handling in conj. * src/cgi-bin/conj.scm4: Add error handling. * src/ellinika/conjugator.scm: Throw 'conjugator-error instead of calling (error). * src/ellinika/elmorph.c: Use ~A in error messages when referring to elstrs. Guile's ~S sucks on UTF-8. * src/ellinika/utf8scm.c: Likewise. * style.css (.error): Output in red. --- src/ellinika/conjugator.scm | 6 ++++-- src/ellinika/elmorph.c | 28 ++++++++++++++-------------- src/ellinika/utf8scm.c | 8 ++++---- 3 files changed, 22 insertions(+), 20 deletions(-) (limited to 'src/ellinika') diff --git a/src/ellinika/conjugator.scm b/src/ellinika/conjugator.scm index 41575c2..8172686 100644 --- a/src/ellinika/conjugator.scm +++ b/src/ellinika/conjugator.scm @@ -178,7 +178,8 @@ WHERE verb=\"~A\" AND voice=\"~A\" AND thema=\"~A\"" ((elstr-suffix? verb "ομαι") (elstr-trim verb -4)) (else - (error "cannot handle ~A~%" verb)))) + (throw 'conjugator-error 'conjugator-error-input + "cannot handle ~A" (list (force-string verb)))))) (define (complement-verb-info vinfo verb voice thema) ; (format #t "COMPLEMENT ~A~%" vinfo) @@ -417,7 +418,8 @@ AND c.tense=\"~A\" AND c.flect = f.ident ORDER by fold" (else 3))) obj)))) (else - (error "invalid accent character" acc)))) + (throw 'conjugator-error 'conjugator-error-db + "invalid accent character ~A" (list acc))))) (conj-info #:flect conj) accmap))) (if (conj-info #:particle conj) diff --git a/src/ellinika/elmorph.c b/src/ellinika/elmorph.c index 56bead3..90a156d 100644 --- a/src/ellinika/elmorph.c +++ b/src/ellinika/elmorph.c @@ -265,7 +265,7 @@ force_elstr(struct elstr **ep, SCM scm, int sylopt, free(str); if (newscm == SCM_EOL) scm_misc_error(func_name, - "Invalid input string: ~S", + "Invalid input string: ~A", scm_list_1(scm)); scm = newscm; elstr = (struct elstr*) SCM_CDR(newscm); @@ -357,7 +357,7 @@ SCM_DEFINE_PUBLIC(scm_elstr_syllable_prop, "elstr-syllable-prop", if (num > elstr->nsyl) scm_misc_error(FUNC_NAME, "cannot get syllable #~S: not enough syllables: ~S", - scm_list_2(el, n)); + scm_list_2(n, el)); num = elstr->nsyl - num; return scm_list_3(scm_from_uint(elstr->sylmap[num].char_start), @@ -406,7 +406,7 @@ SCM_DEFINE_PUBLIC(scm_elstr_syllable, "elstr-syllable", if (num > elstr->nsyl) scm_misc_error(FUNC_NAME, "cannot get syllable #~S: not enough syllables: ~S", - scm_list_2(el, n)); + scm_list_2(n, el)); num = elstr->nsyl - num; if (utf8_wc_to_mbstr(elstr->str + elstr->sylmap[num].char_start, elstr->sylmap[num].char_count, @@ -437,7 +437,7 @@ SCM_DEFINE_PUBLIC(scm_elstr_character, "elstr-character", if (num >= elstr->len) scm_misc_error(FUNC_NAME, "cannot get character #~S: not enough characters: ~S", - scm_list_2(el, n)); + scm_list_2(n, el)); len = utf8_wctomb(r, elstr->str[num]); if (len <= 0) scm_misc_error(FUNC_NAME, @@ -574,7 +574,7 @@ _elstr_set_accent(SCM el, SCM n, int destructive, const char *func_name) num = scm_to_uint(n); if (num == 0 | num > elstr->nsyl) scm_misc_error(func_name, - "cannot set accent on syllable #~S: not enough syllables: ~S", + "cannot set accent on syllable #~S: not enough syllables: ~A", scm_list_2(n, el)); acc_num = elstr->nsyl - num; @@ -607,7 +607,7 @@ _elstr_set_accent(SCM el, SCM n, int destructive, const char *func_name) } if (!phoneme) scm_misc_error(func_name, - "cannot set accent on syllable #~S of ~S: " + "cannot set accent on syllable #~S of ~A: " "INTERNAL ERROR", scm_list_2(n, el)); else if (phoneme->flags & CHF_DIPHTHONG) @@ -659,12 +659,12 @@ _elstr_set_accent_on_char(SCM el, SCM n, int destructive, const char *func_name) num = scm_to_uint(n); if (num > elstr->len) scm_misc_error(func_name, - "cannot set accent on character #~S: not enough characters: ~S", - scm_list_2(el, n)); + "cannot set accent on character #~S: not enough characters: ~A", + scm_list_2(n, el)); if (!elchr_isvowel(elstr->str[num])) scm_misc_error(func_name, - "cannot set accent on character #~S: not a vowel: ~S", - scm_list_2(el, n)); + "cannot set accent on character #~S: not a vowel: ~A", + scm_list_2(n, el)); if (destructive) scm = SCM_UNSPECIFIED; @@ -718,8 +718,8 @@ SCM_DEFINE_PUBLIC(scm_elstr_char_prop_bitmask, "elstr-char-prop-bitmask", num += elstr->len; if (num >= elstr->len) scm_misc_error(FUNC_NAME, - "cannot get character #~S: not enough characters: ~S", - scm_list_2(el, n)); + "cannot get character #~S: not enough characters: ~A", + scm_list_2(n, el)); return scm_from_uint(elchr_flags(elstr->str[num])); } #undef FUNC_NAME @@ -763,8 +763,8 @@ SCM_DEFINE_PUBLIC(scm_elstr_char_phoneme, "elstr-char-phoneme", num += elstr->len; if (num >= elstr->len) scm_misc_error(FUNC_NAME, - "cannot get character #~S: not enough characters: ~S", - scm_list_2(el, n)); + "cannot get character #~S: not enough characters: ~A", + scm_list_2(n, el)); return scm_from_uint(elchr_phoneme(elstr->str[num])); } #undef FUNC_NAME diff --git a/src/ellinika/utf8scm.c b/src/ellinika/utf8scm.c index 89f5fba..1cb7f76 100644 --- a/src/ellinika/utf8scm.c +++ b/src/ellinika/utf8scm.c @@ -35,7 +35,7 @@ SCM_DEFINE_PUBLIC(scm_utf8_toupper, "utf8-toupper", 1, 0, 0, str = scm_to_locale_string(string); if (utf8_toupper(str, strlen(str))) scm_misc_error(FUNC_NAME, - "cannot convert to upper case: ~S", + "cannot convert to upper case: ~A", scm_list_1(string)); scm = scm_from_locale_string(str); free(str); @@ -55,7 +55,7 @@ SCM_DEFINE_PUBLIC(scm_utf8_tolower, "utf8-tolower", 1, 0, 0, str = scm_to_locale_string(string); if (utf8_tolower(str, strlen(str))) scm_misc_error(FUNC_NAME, - "cannot convert to lower case: ~S", + "cannot convert to lower case: ~A", scm_list_1(string)); scm = scm_from_locale_string(str); free(str); @@ -90,7 +90,7 @@ SCM_DEFINE_PUBLIC(scm_utf8_escape, "utf8-escape", 1, 1, 0, if (utf8_mbstr_to_wc(s, &wptr, &wlen)) scm_misc_error(FUNC_NAME, - "cannot convert ~S to UTF-8", + "cannot convert ~A to UTF-8", scm_list_1(string)); free(s); @@ -106,7 +106,7 @@ SCM_DEFINE_PUBLIC(scm_utf8_escape, "utf8-escape", 1, 1, 0, if (utf8_mbstr_to_wc(s, &escbase, &esclen)) { free(wptr); scm_misc_error(FUNC_NAME, - "cannot convert ~S to UTF-8", + "cannot convert ~A to UTF-8", scm_list_1(escapable)); } escptr = escbase; -- cgit v1.2.1