Running the following code to create a new Database (PostgreSQL 11.3) row:
const supplier = await Supplier.create(
Object.assign({}, entityData, {
last_activity_date: sails.services.datehelper.GetTimeNow(),
account: supplierParams.supplier,
monitored: !!activeRegistry,
verified: true
})
);
error: Error (E_UNKNOWN) :: Encountered an unexpected error
at new WLError (invoice-portal/node_modules/waterline/lib/waterline/error/WLError.js:25:15)
at invoice-portal/node_modules/waterline/lib/waterline/model/lib/defaultMethods/save.js:188:17
at invoice-portal/node_modules/waterline/node_modules/async/lib/async.js:52:16
at invoice-portal/node_modules/waterline/node_modules/async/lib/async.js:550:17
at invoice-portal/node_modules/waterline/node_modules/async/lib/async.js:544:17
at _arrayEach (invoice-portal/node_modules/waterline/node_modules/async/lib/async.js:85:13)
at Immediate.taskComplete (invoice-portal/node_modules/waterline/node_modules/async/lib/async.js:543:13)
at runCallback (timers.js:789:20)
at tryOnImmediate (timers.js:751:5)
at processImmediate [as _immediateCallback] (timers.js:722:5)
I added some additional logging (finally in the correct place) in invoice-portal/node_modules/waterline/lib/waterline/model/lib/defaultMethods/save.js to catch all of the saved data and it was not the creation of the Supplier that failed but the insert of invoice row item (which happens after supplier is created/updated).
Some timing/correlation glitch makes Sails throw the error after the Supplier is created (probably at the end of the transaction) why I was looking at the wrong place... Fixing the validation error for the Invoice Item data solved the issue!