After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 482313 - gregex: no way to tell why compilation failed
gregex: no way to tell why compilation failed
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gregex
unspecified
Other All
: Normal major
: ---
Assigned To: Marco Barisione
gtkdev
Depends on:
Blocks: 482319
 
 
Reported: 2007-10-01 17:52 UTC by Morten Welinder
Modified: 2007-12-03 18:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Return the (translatable) reason why compilation failed (16.59 KB, patch)
2007-11-19 13:23 UTC, Marco Barisione
none Details | Review
When compilation fails use a translatable error message and return the reason why it failed (for trunk) (17.04 KB, patch)
2007-11-22 22:19 UTC, Marco Barisione
accepted-commit_now Details | Review
When compilation fails use a translatable error message (for glib-2-14) (5.02 KB, patch)
2007-11-22 22:22 UTC, Marco Barisione
none Details | Review
When compilation fails use a translatable error message (for glib-2-14) (5.02 KB, patch)
2007-11-22 22:23 UTC, Marco Barisione
accepted-commit_now Details | Review

Description Morten Welinder 2007-10-01 17:52:32 UTC
g_regex_new does not return a reason why compilation failed.
It ought to return the error code from pcre_compile2 somehow.

Here's what g_regex_new does do:

      GError *tmp_error = g_error_new (G_REGEX_ERROR, 
				       G_REGEX_ERROR_COMPILE,
				       _("Error while compiling regular "
					 "expression %s at char %d: %s"),
				       pattern, erroffset, errmsg);

This is not useful.

1. erroffset is a byte offset, not a character count.
2. errmsg is untranslated and the final result is thus not something I
   can show to the user.
Comment 1 Marco Barisione 2007-10-01 19:14:08 UTC
I will convert erroffset from byte offset to character offset before using it.

I could add an array with known (and translatable) error codes, and use it instead of errmsg. If the error code is not known (because you are using a new version of pcre) then I could just use the untranslated string.

Is it enough for your needs?
Comment 2 Morten Welinder 2007-10-01 23:51:39 UTC
It would be enough for my current needs -- which is to be able to report
errors to the user -- but I really think the actual error code should be
embedded in the GError in roughly the same way that errno is embedded in
errors from gfileutils.c

And unknown error codes you can simply map to the generic "bad pattern"
error.
Comment 3 Matthias Clasen 2007-11-10 02:12:48 UTC
Do you have a patch, Marco ?
Comment 4 Marco Barisione 2007-11-14 20:58:31 UTC
Sorry, my plan was to fix this last week but university is taking too much time.
After my last exam on Friday I will have time to work on this.
Comment 5 Marco Barisione 2007-11-19 13:17:46 UTC
I committed the fix for using the character offset instead of the byte offset to trunk and the glib-2-14 branch.
Comment 6 Marco Barisione 2007-11-19 13:23:57 UTC
Created attachment 99328 [details] [review]
Return the (translatable) reason why compilation failed

This patch adds new errors to GRegexError, this means that I can commit it only to trunk, isn't it?
In this case I can backport the patch for glib 2.14 so we can have translated names without adding new symbols.

Please check if the new error names have a decent and correct name.
Comment 7 Marco Barisione 2007-11-19 13:26:16 UTC
And I have also to add "Since 2.16" in the documentation for the new errors.
Comment 8 Morten Welinder 2007-11-19 21:24:07 UTC
I would like to see more of this in 2.14.  Dual-language error messages
is not something we can present to users.

Also, please make sure the API says that new items might be added, i.e.,
that users should be prepared to map such errors to G_REGEX_ERROR_COMPILE
or some such.

-      regex->extra = pcre_study (regex->pcre_re, 0, &errmsg);
+      regex->extra = pcre_study (regex->pcre_re, 0, (const gchar **)&errmsg);

Isn't this an alias violation that causes gcc to complain?
Comment 9 Marco Barisione 2007-11-19 21:38:21 UTC
For 2.14 I can just translate the message but without adding new error codes.

No, gcc doesn't complain about alias violations.
Comment 10 Marco Barisione 2007-11-22 22:19:40 UTC
Created attachment 99500 [details] [review]
When compilation fails use a translatable error message and return the reason why it failed (for trunk)

What do you mean exactly with "Also, please make sure the API..."?
Comment 11 Marco Barisione 2007-11-22 22:22:18 UTC
Created attachment 99501 [details] [review]
When compilation fails use a translatable error message (for glib-2-14)

If you don't have any objection I'm going to commit this and the other patch tomorrow.
Comment 12 Marco Barisione 2007-11-22 22:23:32 UTC
Created attachment 99502 [details] [review]
When compilation fails use a translatable error message (for glib-2-14)

If you don't have any objection I'm going to commit this and the other patch tomorrow.
Comment 13 Morten Welinder 2007-11-23 01:53:52 UTC
> What do you mean exactly with "Also, please make sure the API..."?

I mean that you should document that new error codes might be added (if
PCRE is ungraded) and that the caller should be prepared for that.

Patch looks good to me (visually -- untested).
Comment 14 Matthias Clasen 2007-11-23 05:52:44 UTC
Compilation of the regular expression failed with a generic error.

I'd shorten that to 

Compilation of the regular expression failed.

The "generic error" doesn't really add anything, and the shorter message
is also more in sync with the one about optimization.


Other than that, the patch looks ok to me, too.

Since it adds new translatable strings, committing it to 2.14 will break
the string freeze, thus you'll want to send a mail to gnome-i18n to notify
translators about this.
Comment 15 Marco Barisione 2007-12-03 18:58:46 UTC
Fixed in trunk and glib-2-14.