Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug that allowed to create an annotation with an empty text. #76

Merged
merged 1 commit into from
Jul 30, 2020

Conversation

cage2
Copy link
Collaborator

@cage2 cage2 commented Jul 24, 2020

Hi Bastibe!

I think i introduced a regression in the near past because i do not think i met this bug until now.
If you try to add an annotation and pass to the minibuffer an empty string as annotation text an error occurs, fontification fails and a text is annotated without no actual text of the annotation.

To prevent this annotate-create-annotation now signals a condition (error) if
is asked to create an annotation with no annotation text. The caller supposed to "catch" this condition and manage the
condition in a meaningful way (so far: print an error message to the user ;-) )

I have added a a minimal hierarchy of custom errors annotate-error as parent and annotate-empty-annotation-text-error as child.

Bye!!
C.

  annotate-create-annotation now signals a condition (error) if
  an user is asked to create an annotation with no annotation text.
@bastibe
Copy link
Owner

bastibe commented Jul 24, 2020

Hi Cage!

Good catch with that bug!

Currently, you are raising an exception when an annotation with an empty text is created. When an annotation is changed to an empty annotation, however, we interpret that as the user wanting to delete the annotation. It might be more consistent to do the same thing for creation, and do not create an annotation. Or do you see a use case for catching that exception?

@cage2
Copy link
Collaborator Author

cage2 commented Jul 25, 2020

Hi Cage!

Hi bastibe!!

Good catch with that bug!

It was sitting there for month i guess, i was surprised i did not step into it until now! :)

Currently, you are raising an exception when an annotation with an empty text is created. When an annotation is changed to an empty annotation, however, we interpret that as the user wanting to delete the annotation. It might be more consistent to do the same thing for creation, and do not create an annotation. Or do you see a use case for catching that exception?

Let's me see if i have interpreted your question correctly (always my bad English :/)

This fragment of code:

                   (condition-case error-message
                       (annotate-create-annotation start end annotation-text nil)
                     (annotate-empty-annotation-text-error
                      (user-error "Annotation text is empty.")))))))

is equivalent to the following:

(if (annotate-string-empty-p annotation-text)
    (user-error "Annotation text is empty.")
  (annotate-create-annotation start end annotation-text nil))

is the code just above what you suggest?

No annotation is created in both case, in principle i would prefer the first because, in the future the function annotate-create-annotation could signal more different conditions and catching a new condition could be added to existing code with no efforts.

But the code in the second snippet appears more readable so it does makes sense to me too, i can not decide which one i prefer! :D

Bye!!
C.

@bastibe
Copy link
Owner

bastibe commented Jul 27, 2020

Sorry for being unclear.

I was wondering if you have any plans for the exceptions? In other user-error cases, we either ignored errors, or printed a warning message. But we didn't raise an exception.

So why raise an exception here instead of ignoring the error? I am not against raising an exception. Just wondering why we would raise one here, and not elsewhere.

@cage2
Copy link
Collaborator Author

cage2 commented Jul 27, 2020 via email

@bastibe
Copy link
Owner

bastibe commented Jul 29, 2020

Good idea about separating our error signaling mechanisms in user-facing functions (print errors or ignore them silently), and developer-facing functions (raise exceptions). I like that!

@cage2
Copy link
Collaborator Author

cage2 commented Jul 29, 2020 via email

@bastibe
Copy link
Owner

bastibe commented Jul 30, 2020

I don't have a preference, either. But since this PR is ready to merge already, how about we merge, and do the signaling change separately?

@cage2
Copy link
Collaborator Author

cage2 commented Jul 30, 2020

Hi @bastibe !

Sure i am going to follow your suggestion! Merging this one and starting a new PR to explore which are the functions that could signal errors.

Bye!
C.

@cage2 cage2 closed this Jul 30, 2020
@cage2 cage2 reopened this Jul 30, 2020
@cage2 cage2 merged commit d4b555d into bastibe:master Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants