Bug 21685

Summary: Name our exceptions consistently
Product: Koha Reporter: Jonathan Druart <jonathan.druart>
Component: Architecture, internals, and plumbingAssignee: Bugs List <koha-bugs>
Status: In Discussion --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: kyle, m.de.rooy, martin.renvoize, nick, tomascohen
Version: unspecified   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=21337
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:

Description Jonathan Druart 2018-10-26 14:04:27 UTC
Few examples of inconsistencies:

*
Koha::Exceptions::WrongParameter
Koha::Exceptions::BadParameter

*
Koha::Exceptions::CannotDeleteDefault
Koha::Exceptions::Patron::FailedDelete

*
Koha::Exceptions::Account::IsNotCredit
Koha::Exceptions::Password::Invalid
=> IsNotCredit vs NotCredit
=> IsNotValid vs Invalid vs NotValid

*
Koha::Exceptions::DuplicateObject
Koha::Exceptions::Object::DuplicateID

It would be good a write a guideline and adapt existing occurrences.
Comment 1 Jonathan Druart 2018-10-26 18:37:08 UTC
CCing some of you, how do you feel about that? Any good practices you have in mind? It would be good to have something on the wiki.
Comment 2 Martin Renvoize (ashimema) 2019-12-13 09:26:53 UTC
Agreed it would be nice to build a consistent pattern and add a guideline to help work towards that... we also don't always subclass and so exceptions are hard to find sometimes which I think is what leads to the nearly duplicate ones you have discovered.

I'd even go so far as to ask the question of whether it's worth us starting to take on a more consistent approach with our objects in general.. We already actually have Moo as a dependency, we could start using some of its recommendations today if we wanted to for type checking etc.  We're also doing a poor mans version of method signatures in a few cases now.. perhaps we should start advocating something there too?
Comment 3 Martin Renvoize (ashimema) 2019-12-13 09:30:58 UTC
(In reply to Martin Renvoize from comment #2)
> I'd even go so far as to ask the question of whether it's worth us starting
> to take on a more consistent approach with our objects in general.. We
> already actually have Moo as a dependency, we could start using some of its
> recommendations today if we wanted to for type checking etc.  We're also
> doing a poor mans version of method signatures in a few cases now.. perhaps
> we should start advocating something there too?

To clarify that a bit.. I'm thinking of something along the lines of Function::Parameters + Type::Tiny