Loopback-datasource-juggler: Server crashes when entering invalid date

Created on 6 Feb 2017  路  5Comments  路  Source: loopbackio/loopback-datasource-juggler

Bug or feature request

  • [x] Bug
  • [ ] Feature request

Description of feature (or steps to reproduce if bug)

  1. Add a model with a property of the type date;
  2. Make a custom function (e.g. with Async) which updates the date property;
  3. Call this function with an invalid date as a string.
  4. The server crashes.

Remark: It does not happen when you update the model via a non-wrapped function call, because the error is catched by the error handler mechanism of LoopBack.

Link to sample repo to reproduce issue (if bug)

See: https://github.com/joostdebruijn/loopback-date-issue

  1. Clone the repo.
  2. Run npm install.
  3. Start the server with node .
  4. Create notes:
POST /api/Notes
[
  {
    "title": "Test 1",
    "content": "Test",
    "date": "2017-02-06"
  },
  {
    "title": "Test 2",
    "content": "Test",
    "date": "2017-02-06"
  }
]
  1. Update notes in bulk:
POST /api/Notes/updateDatesInBulk
[
  {"id": 1, "date": "thiswillfail"}
]
  1. The server will crash.

Expected result

Receive a validation error in the callback which could be handled.

Actual result (if bug)

The server crashes because the error is thrown, trace:

\node_modules\loopback-datasource-juggler\lib\model-builder.js:531
    throw new Error(g.f('Invalid date: %s', arg));

Error: Invalid date: thiswillfail
    at DateType (node_modules\loopback-datasource-juggler\lib\model-builder.js:531:11)
    at ModelConstructor.set [as startTime] (node_modules\loopback-datasource-juggler\lib\model-builder.js:467:81)
    at ModelConstructor.setAttribute (node_modules\loopback-datasource-juggler\lib\dao.js:2760:14)
    at ModelConstructor.setAttributes (node_modules\loopback-datasource-juggler\lib\dao.js:2793:10)
    at validateAndSave (node_modules\loopback-datasource-juggler\lib\dao.js:3101:12)
    at node_modules\loopback-datasource-juggler\lib\dao.js:3085:7
    at doNotify (node_modules\loopback-datasource-juggler\lib\observer.js:99:49)
    at doNotify (node_modules\loopback-datasource-juggler\lib\observer.js:99:49)
    at doNotify (node_modules\loopback-datasource-juggler\lib\observer.js:99:49)
    at doNotify (node_modules\loopback-datasource-juggler\lib\observer.js:99:49)
    at Function.ObserverMixin._notifyBaseObservers (node_modules\loopback-datasource-juggler\lib\observer.js:122:5)
    at Function.ObserverMixin.notifyObserversOf (node_modules\loopback-datasource-juggler\lib\observer.js:97:8)
    at Function.ObserverMixin._notifyBaseObservers (node_modules\loopback-datasource-juggler\lib\observer.js:120:15)
    at Function.ObserverMixin.notifyObserversOf (node_modules\loopback-datasource-juggler\lib\observer.js:97:8)
    at Function.ObserverMixin._notifyBaseObservers (node_modules\loopback-datasource-juggler\lib\observer.js:120:15)
    at Function.ObserverMixin.notifyObserversOf (node_modules\loopback-datasource-juggler\lib\observer.js:97:8)

Additional information (Node.js version, LoopBack version, etc)

Node.js: 7.5.0
loopback: 3.2.1
loopback-datasource-juggler: 3.2.0
loopback-connector-mysql: 3.0.0

This issue is also mentioned in the LoopBack-project, see https://github.com/strongloop/loopback/issues/2856, however it seems that the origin of this issue is in the datasource-juggler so I posted it here.

bug

All 5 comments

Confirmed. Taking this for our backlog, thanks for the report, and for the detailed reproduction.

Verified with latest code. For the example given above, it will give error code 500 and not crashing the server.

@kjdelisle @siddhipai, we had this issue verified and in to be released. Do you know why we put it back to in-progress? The PR has landed.

sorry.. close it accidentally. Reopening it.

Was this page helpful?
0 / 5 - 0 ratings