gramps icon indicating copy to clipboard operation
gramps copied to clipboard

Avoid application crash on invalid user input

Open jpschewe opened this issue 2 years ago • 7 comments

This is a fix for bug 0012658. If the user inputs an invalid date this change keeps the application from crashing when such a date is found.

jpschewe avatar Jul 11 '22 11:07 jpschewe

I don't like this. You must verify your data is correct. And this is your problem. The user must be warned that his data is incorrect. There is a better solution for this.

SNoiraud avatar Jul 11 '22 14:07 SNoiraud

Your patch doesn't work when you have spanned date. Many reports will not work if you don't want to correct the dates.

I propose the following patch for the narrativeweb:

@@ -2873,8 +2873,13 @@ class BasePage: # pylint: disable=C1001
                 if self.reference_sort:
                     role = ""
                 elif role[1:2] == ':':
-                    # cal is the original calendar
-                    cal, role = role.split(':')
+                    if len(role.split(':')) > 2:
+                        print("Invalid date :", role[2:], " for :", gid,
+                              ". Please, use the 'verify the data' tool to correct this.")
+                        cal, role = role.split(':', 1)
+                    else:
+                        # cal is the original calendar
+                        cal, role = role.split(':')
                     # conver ISO date to Date for translation.
                     # all modifiers are in english, so convert them
                     # to the local language

SNoiraud avatar Jul 11 '22 16:07 SNoiraud

That does seem better, however where does the output go? Is there a way to report this to the user?

If there isn't a direct way to send a message raising an exception with the information would give the user a chance to figure out what is broken.

                    raise RuntimeError("Invalid date :", role[2:], " for individual with ID:", gid,
                          ". Please, use the 'verify the data' tool to correct this.")

jpschewe avatar Jul 12 '22 01:07 jpschewe

however where does the output go?

All the results go in the gramps.log if you have one, or on the terminal where you started gramps.

We can show a warning window for this. But this case is so rare (you are the first in 15 years) that I think the print is sufficient.

SNoiraud avatar Jul 12 '22 06:07 SNoiraud

OK, if I'm the first to ask, then the print sounds fine. Would you like me to update this PR or just close it out?

jpschewe avatar Jul 12 '22 13:07 jpschewe

Yes please. This PR don't need to be closed.

SNoiraud avatar Jul 12 '22 16:07 SNoiraud

OK, I just pushed changes that will output the warning to the log or stdout. I just tested and I saw the output on stdout.

jpschewe avatar Jul 13 '22 01:07 jpschewe

@SNoiraud Is this ready to be merged?

Nick-Hall avatar May 14 '23 20:05 Nick-Hall