Spring Batch
  1. Spring Batch
  2. BATCH-587

more informative exception messages in SpringValidator

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.0
    • Fix Version/s: 1.0.1
    • Component/s: Infrastructure
    • Labels:
      None

      Description

      It would be interesting for logging purposes to have the error item in org.springframework.batch.item.validator.ValidationException (just like FlatFileParseException
      contains the error line and line number).

      Something like err.getRejectedValue() or err.getObjectInError() would do it.

      Some links : http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/validation/ObjectError.html or http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/validation/FieldError.html (if we want to put informations about the fields themselves that failed validation.

      See also forum : http://forum.springframework.org/showpost.php?p=174771&postcount=13

        Activity

        Hide
        Robert Kasanicky added a comment -

        I think for 1.0.1 we can improve the message string created in the SpringValidator adapter class to be more informative (by including item.toString). If the sole purpose for having access to the item in exception is logging this should help a lot.

        I'm not sure including the item itself and/or the validation result object (BeanPropertyBindingResult in spring validator case) would be useful - both item and validation result can be arbitrary objects, so you would need to use instanceof checks or reflection to get more than "toString" information.

        Show
        Robert Kasanicky added a comment - I think for 1.0.1 we can improve the message string created in the SpringValidator adapter class to be more informative (by including item.toString). If the sole purpose for having access to the item in exception is logging this should help a lot. I'm not sure including the item itself and/or the validation result object (BeanPropertyBindingResult in spring validator case) would be useful - both item and validation result can be arbitrary objects, so you would need to use instanceof checks or reflection to get more than "toString" information.
        Hide
        Robert Kasanicky added a comment -

        Enriched exception messages in SpringValidator - item and validation errors are included in the string.

        @adrian: does this solve your logging usecase?

        Show
        Robert Kasanicky added a comment - Enriched exception messages in SpringValidator - item and validation errors are included in the string. @adrian: does this solve your logging usecase?
        Hide
        adrian added a comment -

        <quote>Does this solve your logging usecase</quote>
        -> It 's perfect for me for the 1.0.1. I'll test it tomorrow.
        Thanks very much Robert !

        I need also to get the detailed item - I'm writing a record in a db table for every skipped item (but franckly I don't know if the item_detail column will be used).
        So for this latter usage, I'll wait for my customers real needs - and if they need it I'll wait for Spring Batch 1.1 facilities (as Lucas told in this post :http://forum.springframework.org/showpost.php?p=174758&postcount=11).

        Thanks once more for the reactivity !!!

        Show
        adrian added a comment - <quote>Does this solve your logging usecase</quote> -> It 's perfect for me for the 1.0.1. I'll test it tomorrow. Thanks very much Robert ! I need also to get the detailed item - I'm writing a record in a db table for every skipped item (but franckly I don't know if the item_detail column will be used). So for this latter usage, I'll wait for my customers real needs - and if they need it I'll wait for Spring Batch 1.1 facilities (as Lucas told in this post : http://forum.springframework.org/showpost.php?p=174758&postcount=11 ). Thanks once more for the reactivity !!!
        Hide
        Robert Kasanicky added a comment -

        edited the issue summary to reflect what has been done to fix it - we can start a new issue for including the item itself in the exception if desired.

        Show
        Robert Kasanicky added a comment - edited the issue summary to reflect what has been done to fix it - we can start a new issue for including the item itself in the exception if desired.
        Hide
        adrian added a comment -

        Tested it, works fine.

        Thanks !

        Sample log output :
        Validation failed for com.xxx.yyy.batch.modele.domain.Client@6ba06ba[ChargeClientele=7,numRib=6592236261555,dateAdhesion=Thu Jul 05 00:00:00 CEST 2007,isCorrect=true,contrats=[],identifiant=203494,adresse=com.xxx.yyy.batch.modele.domain.Adresse@6ae06ae[rue=55, Rue Gustave Eiffel,ville=Paris,codePostal=75000,pays=5,paysNaissance=3,villeNaissance=Paris,codePostalNaissance=43000],civilite=4,situationFamiliale=1,nomPatrimonial=ROUXP,nomMarital=,prenom=Pierre,prenom2=Pierre,codeSecu=208642935108231,dateNaissance=Mon Aug 28 00:00:00 CET 1363]:
        Field error in object 'item' on field 'dateNaissance': rejected value [Mon Aug 28 00:00:00 CET 1363]; codes [Client.dateNaissance[erreur sur date naissance].item.dateNaissance,Client.dateNaissance[erreur sur date naissance].dateNaissance,Client.dateNaissance[erreur sur date naissance].java.util.Date,Client.dateNaissance[erreur sur date naissance]]; arguments []; default message [erreur sur date naissance]

        Show
        adrian added a comment - Tested it, works fine. Thanks ! Sample log output : Validation failed for com.xxx.yyy.batch.modele.domain.Client@6ba06ba[ChargeClientele=7,numRib=6592236261555,dateAdhesion=Thu Jul 05 00:00:00 CEST 2007,isCorrect=true,contrats=[],identifiant=203494,adresse=com.xxx.yyy.batch.modele.domain.Adresse@6ae06ae [rue=55, Rue Gustave Eiffel,ville=Paris,codePostal=75000,pays=5,paysNaissance=3,villeNaissance=Paris,codePostalNaissance=43000] ,civilite=4,situationFamiliale=1,nomPatrimonial=ROUXP,nomMarital=,prenom=Pierre,prenom2=Pierre,codeSecu=208642935108231,dateNaissance=Mon Aug 28 00:00:00 CET 1363]: Field error in object 'item' on field 'dateNaissance': rejected value [Mon Aug 28 00:00:00 CET 1363] ; codes [Client.dateNaissance [erreur sur date naissance] .item.dateNaissance,Client.dateNaissance [erreur sur date naissance] .dateNaissance,Client.dateNaissance [erreur sur date naissance] .java.util.Date,Client.dateNaissance [erreur sur date naissance] ]; arguments []; default message [erreur sur date naissance]
        Hide
        Dave Syer added a comment -

        Assume closed as resolved and released

        Show
        Dave Syer added a comment - Assume closed as resolved and released

          People

          • Assignee:
            Robert Kasanicky
            Reporter:
            adrian
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: