synth icon indicating copy to clipboard operation
synth copied to clipboard

Unhelpful error on underspecifying or mis-specifying a `datetime` value

Open llogiq opened this issue 4 years ago • 1 comments

Describe the bug The error when specifying a date format for a time or vice versa, or missing a minutes or days

To Reproduce Steps to reproduce the behavior:

  1. Schema (if applicable)
{
   "type": "array",
   "length": 1,
   "content": {
       "type": "object",
       "date": {
          "type": "string",
          "date_time": {
              "format": "%Y-%m-%d",
              "subtype": "naive_time",
              "begin": "1999-01-01",
              "end": "2199-31-12"
          }
       }
   }
}
  1. See error
Error: Unable to open the namespace

Caused by:
    0: at file 7_datetime/datetime.json
    1: Failed to parse collection
    2: input is not enough for unique date and time at line 16 column 1

Expected behavior

Error: The `datetime` you specified at line 16 column 1 has no specified hours, minutes and seconds field

As an alternative, the generator could have defaults, e.g. when specifying a time with %H, the minutes could be set to 0 automatically. This is already done for seconds. However, if this solution is taken, a warning should be emitted if no fields are non-default.

Environment (please complete the following information):

  • OS: any
  • Version: 0.5.6

llogiq avatar Oct 07 '21 07:10 llogiq

I cannot reproduce this issue:

hbina@akarin:~/git/synth$ ./target/debug/synth version
synth 0.5.6
hbina@akarin:~/git/synth$ cat issues/issue_194/schema.json 
{
    "type": "array",
    "length": 1,
    "content": {
        "type": "object",
        "date": {
           "type": "string",
           "date_time": {
               "format": "%Y-%m-%d",
               "subtype": "naive_time",
               "begin": "1999-01-01",
               "end": "2199-31-12"
           }
        }
    }
 }
hbina@akarin:~/git/synth./target/debug/synth generate issues/issue_194/
Error: Unable to open the namespace

Caused by:
    0: at file issues/issue_194/schema.json
    1: Failed to parse collection
    2: unknown variant `date_time`, expected one of `pattern`, `faker`, `categorical`, `serialized`, `uuid`, `truncated`, `format` at line 16 column 2

If I fix the generator for this,

hbina@akarin:~/git/synth$ cat issues/issue_194/schema.json 
{
  "type": "array",
  "length": 1,
  "content": {
    "type": "object",
    "date": {
      "type": "date_time",
      "format": "%Y-%m-%d",
      "subtype": "naive_date",
      "begin": "1999-01-01",
      "end": "2199-31-12"
    }
  }
}
hbina@akarin:~/git/synth$ ./target/debug/synth generate issues/issue_194/
Error: Unable to open the namespace

Caused by:
    0: at file issues/issue_194/schema.json
    1: Failed to parse collection
    2: input is out of range at line 14 column 1

The program kindly complains that the month range is invalid (from 01 to 31). Fixing that still cannot produce the error you described,

hbina@akarin:~/git/synth$ cat issues/issue_194/schema.json 
{
  "type": "array",
  "length": 1,
  "content": {
    "type": "object",
    "date": {
      "type": "date_time",
      "format": "%Y-%m-%d",
      "subtype": "naive_date",
      "begin": "1999-01-01",
      "end": "2199-04-12"
    }
  }
}
hbina@akarin:~/git/synth$ ./target/debug/synth generate issues/issue_194/
{"schema":[{"date":"2153-08-11"}]}

hbina avatar Oct 18 '21 14:10 hbina