invoice2data icon indicating copy to clipboard operation
invoice2data copied to clipboard

No format check in new syntax style templates (e.g. type date)

Open bosd opened this issue 1 year ago • 0 comments

Currently there is no type check. I have to admit it is my own mistake. (although might be a common one). Which lead to a crash of my upstream application. I'm opening this ticket to open up a discussion about the prevention of these situations.

I was converting an template from the old syntax to the the new one.

(random example)

fields:
  date:
    - Rechnungsdatum\s+(\w+ \d+, \d{4})

to

fields:
  date:
    parser: regex
    regex: Rechnungsdatum\s+(\w+ \d+, \d{4})

Notice: I forgot to include the type definition. type: date

This made invoice2data sent out an string instead of a datetime object. The upstream application did'nt like this :angry:

I think this is a very common mistake to make.. Specially if your're quickly developing a template. Currently there was no way to notice this error up until the production environment.

Proposed Solution:

  • Should we create a warning in the logger, when the type field is forgotton in the template? Should the log message be on the warning or debug level?? That might lead to a lot of extra debug lines. (Lazy as I am, if my destination type is string, I'm not defining the type in the template.
  • Enforce the type at least for the required fields. In the same way it was with the old syntax. Writing templates is already hard enough. So every little helper to make it easier is welcoming.

bosd avatar Feb 28 '23 20:02 bosd