Declined
Last Updated: 04 Aug 2021 10:18 by ADMIN
Lynn
Created on: 27 Jul 2021 09:25
Category: Kendo UI for jQuery
Type: Bug Report
0
Unclear error when datasource model id field doesn't exist

Hi,

When I call grid.datasource.sync() on a datasource that has a model id defined, but this field is unmapped, I get a cryptic error. You can find a reproducer here: https://dojo.telerik.com/iLacazot

Uncaught TypeError: o is undefined
    setup http://127.0.0.1/a/kendo-ui/js/kendo.all.min.js:28
    create http://127.0.0.1/a/kendo-ui/js/kendo.all.min.js:28
    _promise http://127.0.0.1/a/kendo-ui/js/kendo.all.min.js:28
    Deferred jQuery
    _promise http://127.0.0.1/a/kendo-ui/js/kendo.all.min.js:28
    _send http://127.0.0.1/a/kendo-ui/js/kendo.all.min.js:28
    sync http://127.0.0.1/a/kendo-ui/js/kendo.all.min.js:28
    <anonymous> http://127.0.0.1/a/program/discount/search/:4058


On a slightly related subject; When checking the docs on the model id it seems that the example is missing from this page:

https://docs.telerik.com/kendo-ui/api/javascript/data/model/fields/id

5 comments
ADMIN
Ianko
Posted on: 04 Aug 2021 10:18

Hello Lynn,

It is technically impossible to have proper configuration validation over vanilla JS as models and definitions are ambiguous by nature. Such validation can come with TypeScript where you would be able to define a model by using a Class and that class to be validated. However, with JS you do not have types so that you could get runtime, build-time or intellisense errors about wrong definitions.  

Regards,
Ianko
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Lynn
Posted on: 04 Aug 2021 08:00
So if I understand it correctly, there's no validation done whatsoever when defining the configuration? That would explain a lot of struggles I had with typos or putting configuration on the wrong "indent".

Sounds like an important part of any framework to validate the configuration to alert the developer when something is not right. Will this be implemented in the future? This is one of the most important parts of the developer experience: fail fast, and not after several hours of trying to figure out why something is not doing anything or giving an unclear error.
ADMIN
Ianko
Posted on: 04 Aug 2021 07:52

Hello Lynn,

I am afraid with JS it is not so easy to provide straightforward error messages that would help developers resolve any type of error that may result by misconfiguration of a widget, utility or component. 

In this case, the wrong definition entirely breaks the processing of data operations which results in errors later in the code. Before that, we cannot somehow in code predict what data is going to be fetched and define the model definition as invalid and somehow throw a meaningful error that the id definition is wrong. 

Regards,


Ianko
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Lynn
Posted on: 03 Aug 2021 11:19
I understand that, but as a developer I'd like a clear error message instead of a weird javascript error that I can't trace back to the cause. A typo shouldn't cause 2 hours of trying to figure out why something isn't working. In this case it's a clear framework requirement that the value of this column should refer to an existing field, so the framework should also let the developer know when this value is invalid.
ADMIN
Ianko
Posted on: 03 Aug 2021 11:14

Hi Lynn,

The model that is set with an id field should always have the id field defined and set to a unique value. The DataSource uses that id field to process the items and consider if the item is new or being updated. Thus, when the model is defined with an id field, but it's undefined it is normal JS error to be thrown. 

As for the example, you can refer to this one: https://docs.telerik.com/kendo-ui/api/javascript/data/model/methods/define

Regards,
Ianko
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.