Bug 27833

Summary: Koha::Exceptions::Patron::Attribute::* should have parameters
Product: Koha Reporter: Tomás Cohen Arazi <tomascohen>
Component: Architecture, internals, and plumbingAssignee: Tomás Cohen Arazi <tomascohen>
Status: CLOSED FIXED QA Contact: Martin Renvoize <martin.renvoize>
Severity: enhancement    
Priority: P5 - low CC: fridolin.somers, martin.renvoize
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
This development adds parameters to the extended attributes-related exceptions. This allows better handling.
Version(s) released in:
21.05.00
Bug Depends on: 17828    
Bug Blocks: 27858, 28220    
Attachments: Bug 27833: Make Koha::Exceptions::Patron::Attribute::* have parameters
Bug 27833: Add unit tests
Bug 27833: Make K::P::Attribute add the object to the exception
Bug 27833: Make Koha::Exceptions::Patron::Attribute::* have parameters
Bug 27833: Add unit tests
Bug 27833: Make K::P::Attribute add the object to the exception
Bug 27833: (follow-up) Add InvalidType exception
Bug 27833: Make Koha::Exceptions::Patron::Attribute::* have parameters
Bug 27833: Add unit tests
Bug 27833: Make K::P::Attribute add the object to the exception
Bug 27833: (follow-up) Add InvalidType exception

Description Tomás Cohen Arazi 2021-03-02 12:36:28 UTC
When one of them is thrown, they should carry the failing code and value. This way we can provide better feedback on the UI (or the API).
Comment 1 Tomás Cohen Arazi 2021-03-02 14:19:27 UTC
Created attachment 117516 [details] [review]
Bug 27833: Make Koha::Exceptions::Patron::Attribute::* have parameters

This patch adds a 'field' to this exceptions. They now have an
'attribute' parameter referencing the object itself,

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/Koha/Exceptions.t
=> SUCCESS: Tests pass!
3. Sign off!
Comment 2 Tomás Cohen Arazi 2021-03-02 14:19:30 UTC
Created attachment 117517 [details] [review]
Bug 27833: Add unit tests
Comment 3 Tomás Cohen Arazi 2021-03-02 14:19:33 UTC
Created attachment 117518 [details] [review]
Bug 27833: Make K::P::Attribute add the object to the exception

This patch makes the 'check_unique_id' and '_check_repeatable' methods
pass the 'attribute' parameter when throwing an exception. This way we
can provid emore meaningfull error messages.

To test:
1. Apply the previous patches
2. Run
   $ kshell
  k$ prove t/db_dependent/Koha/Patron/Attributes.t
=> FAIL: The exceptions are not passed the attribute!
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass!
5. Sign off :-D
Comment 4 David Nind 2021-03-02 19:02:44 UTC
Created attachment 117546 [details] [review]
Bug 27833: Make Koha::Exceptions::Patron::Attribute::* have parameters

This patch adds a 'field' to this exceptions. They now have an
'attribute' parameter referencing the object itself,

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/Koha/Exceptions.t
=> SUCCESS: Tests pass!
3. Sign off!

Signed-off-by: David Nind <david@davidnind.com>
Comment 5 David Nind 2021-03-02 19:02:47 UTC
Created attachment 117547 [details] [review]
Bug 27833: Add unit tests

Signed-off-by: David Nind <david@davidnind.com>
Comment 6 David Nind 2021-03-02 19:02:50 UTC
Created attachment 117548 [details] [review]
Bug 27833: Make K::P::Attribute add the object to the exception

This patch makes the 'check_unique_id' and '_check_repeatable' methods
pass the 'attribute' parameter when throwing an exception. This way we
can provid emore meaningfull error messages.

To test:
1. Apply the previous patches
2. Run
   $ kshell
  k$ prove t/db_dependent/Koha/Patron/Attributes.t
=> FAIL: The exceptions are not passed the attribute!
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Comment 7 Tomás Cohen Arazi 2021-03-04 10:42:12 UTC
Created attachment 117676 [details] [review]
Bug 27833: (follow-up) Add InvalidType exception

Working on bug 27857 showed we needed one more exception, for when the
passed attribute type is invalid.

This patch adds the Koha::Exceptions::Patron::Attribute::InvalidType
exception. It adds a format for stringifying it, and tests are added.
The previous exceptions tests lacked one case, so I add them on this
patch as well.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove tt/Koha/Exceptions.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 8 Martin Renvoize 2021-03-04 12:29:54 UTC
Created attachment 117701 [details] [review]
Bug 27833: Make Koha::Exceptions::Patron::Attribute::* have parameters

This patch adds a 'field' to this exceptions. They now have an
'attribute' parameter referencing the object itself,

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/Koha/Exceptions.t
=> SUCCESS: Tests pass!
3. Sign off!

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 9 Martin Renvoize 2021-03-04 12:29:57 UTC
Created attachment 117702 [details] [review]
Bug 27833: Add unit tests

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 10 Martin Renvoize 2021-03-04 12:30:00 UTC
Created attachment 117703 [details] [review]
Bug 27833: Make K::P::Attribute add the object to the exception

This patch makes the 'check_unique_id' and '_check_repeatable' methods
pass the 'attribute' parameter when throwing an exception. This way we
can provid emore meaningfull error messages.

To test:
1. Apply the previous patches
2. Run
   $ kshell
  k$ prove t/db_dependent/Koha/Patron/Attributes.t
=> FAIL: The exceptions are not passed the attribute!
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 11 Martin Renvoize 2021-03-04 12:30:03 UTC
Created attachment 117704 [details] [review]
Bug 27833: (follow-up) Add InvalidType exception

Working on bug 27857 showed we needed one more exception, for when the
passed attribute type is invalid.

This patch adds the Koha::Exceptions::Patron::Attribute::InvalidType
exception. It adds a format for stringifying it, and tests are added.
The previous exceptions tests lacked one case, so I add them on this
patch as well.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove tt/Koha/Exceptions.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 12 Martin Renvoize 2021-03-04 12:30:38 UTC
Good call, I've recently done similar for a few other exceptions.

Code reads well, is tested and works as expected.

Passing QA
Comment 13 Jonathan Druart 2021-04-09 14:40:57 UTC
Pushed to master for 21.05, thanks to everybody involved!
Comment 14 Fridolin Somers 2021-04-19 10:14:37 UTC
Enhancement not pushed to 20.11.x