Closed Qsppl closed 1 week ago
case17_literal: [] is the most important, and most confusing case, imho, so i want to see somethin like this:
"Uncaught TypeError: The value of the [] must be a string, number, or boolean.
This error occurs when you try to assign an undefined value to a property or variable that expects a specific data type. For example: const Model = { // Array anyArr: [], }
To fix this error, you need to make sure that you are assigning a valid value to the property or variable. Here are a few >examples of how you can assign valid values: const Model = { // Primitive permissions: ["user", "admin"], // Nested objects images: [ { url: "https://example.com/large.png", size: "large" }, { url: "https://example.com/medium.png", size: "medium" }, ], }
For more information on working with nested objects and models in Hybrids.js, please refer to the official documentation: https://hybrids.js.org/#/store/model?id=nested-object
The error message is correct - you cannot crate a model with an empty array - it must have a default value inside. Please try to do the same without store.record()
- the error is the same.
The error message could improve, as it takes the value (undefined
), so it's primitive, but it's not a string, boolean or number. However, you can pass there an object too.
The error message is correct - you cannot crate a model with an empty array - it must have a default value inside. Please try to do the same without
store.record()
- the error is the same.The error message could improve, as it takes the value (
undefined
), so it's primitive, but it's not a string, boolean or number. However, you can pass there an object too.
When i try to use [] or {} as value of Model, and see the following error: "Uncaught TypeError: The value of the 'value' must be a string, number or boolean: undefined", I see only one thing, - that in models you can't use JS objects (objects, arrays etc...) , but only primitives... Text of the error message is so confusing, that 3 out of 4 developers who tried to use hybrids in my circle (with me) were sure that you can't use objects and arrays, but only other Models for nested data
https://github.com/hybridsjs/hybrids/issues/270#issuecomment-2326704389
there is a couple of variant of more friendly messages, in which the developers tried to predict the probable cause of this error and tried to immediately help, rather than confuse the user who made this error.
Using an empty object as a property value makes no sense, as it would always be empty. You have to fill it with something...
Here you have docs for nested objects: https://hybrids.js.org/#/store/model?id=nested-object
Nice text for error message, bro)
Using an empty object as a property value makes no sense, as it would always be empty. You have to fill it with something...
Here you have docs for nested objects: https://hybrids.js.org/#/store/model?id=nested-object
I agree, I'll look into it. It should be a simple change. As an author I rarely make those mistakes.
I added two new error messages for empty array and empty nested object. However, I have no intention to "protect" the store from passing built-in objects or other incorrect values.
If a user of the framework would read the docs first, there won't be a problem - as it defines what you can or cannot pass.
The library throws to protect execution from being broken more widely, it's not another layer of the documentation like I try to pass something very stupid and see if the library will show me what I did wrong.
I would never thought, that I could define my model like value: Math
... why does anyone would ever think about it?
Feel free to re-open, if you have any other "real world" scenarios - where after reading documentation it's still not obvious how to use it.
Developers who are just starting to work with hybrids.js often complain that it is difficult for them to understand where they made a mistake and what it was.
I have collected various use cases for Store Definition:
https://codepen.io/qsppl/pen/poXxQqd
There are indeed many cases when, if the library is used incorrectly, it generates an ambiguous error message or does not generate an error at all.
For example, this very common formulation of the error does not tell the truth:
The value of the 'case04' must be a string, number or boolean: undefined
. In fact, a property can be not only a string, number or boolean, but also an object or an array or a getter or a record.Or in case 17 the error now appears:
TypeError: The value of the 'case17_literal' must be a string, number or boolean: undefined
. But a much better fit would be an error likeTypeError: The array item for the 'case17_literal' must be one of the primitive types constructor: ..., ... or ...
Can you make more user-friendly errors so that newbies don't get confused about what they're doing?
P.S. Let me clarify that junior developers also use the library, so you shouldn’t ignore even the most idiotic cases of using the library, for example: