question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

runtime type consistency in expression evaluation.

See original GitHub issue

https://github.com/webzard-io/sunmao-ui/blob/5fe5163733/packages/runtime/src/services/stateStore.ts#L106-L108

Currently, we handle expression evaluation errors with error logs but will return undefined as the result.

This makes components can not predict the types of props in runtime. For example, a component may define a props foo with type number which is required, but if the evaluation throws an error, the component may get undefined as the foo props value.

Possible solution: do not render components in ImplementWrapper when expression evaluation failed.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
MrWindlikecommented, Apr 1, 2022

Yanzhen worries about it will cause silent bug if we fallback to default value. Maybe displaying error message maybe could avoid this problem.

I think the component developers should handle the property’s value could be undefined condition caused by a wrong expression or empty input and consider whether to provide a default value for the property or throw the errors.

Displaying the error messages could help the Sunmao users fix some expression errors but can’t avoid them totally so I think we should handle the wrong expression in some ways.

As to the default value, should we defind default value in spec?

Yes. When switching the JS mode, the expression string is hard to display by the other widgets. Thus, I think maybe set the property to the default value when switching the JS mode.

In addition, I think we should also remain the exampleProperties in the spec because the defaultValue is used to init or reset or be a fallback and the exampleProperties is used to show the base usages of components when inserting the components.

1reaction
Yuyz0112commented, Feb 15, 2022

@tanbowensg

I think this is an issue of soundness.

What’s the expected behavior when a user writes a wrong expression like {{ const a }} and passes the schema to sunmao-ui’s runtime?

Responses I’ve thought about:

  • sunmao-ui’s runtime crash and throw the original expression error to the global scope
  • sunmao-ui’s runtime catch the error and render a mask UI to display the error
  • sunmao-ui’s runtime catch the error in component level and render a mask UI to display the error on top of the corresponding component
  • sunmao-ui’s validator catch the error and show a wrapped error message
  • sunmao-ui’s runtime catch the error and fallback to defaultValue, then log the error to console

Of course, there may be some different ways to handle this in dev/production environments or in runtime/editor scope, but I think we can start from the specific one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Methods for TypeScript runtime type checking - LogRocket Blog
Explore five methods of performing TypeScript type checks at runtime in this post and learn each of their advantages and disadvantages.
Read more >
Evaluating Expressions - Crafting Interpreters
So, to “execute” code, we will evaluate an expression and produce a value. For each kind of ... This type cast happens at...
Read more >
How can I evaluate a C# expression dynamically?
While C# doesn't have any support for an Eval method natively, I have a C# eval program that does allow for evaluating C#...
Read more >
Chapter 15. Expressions
The Java programming language guarantees that the operands of operators appear to be evaluated in a specific evaluation order, namely, from left to...
Read more >
invalid expressions in const-expr and override-expr should be error ...
In the past we discussed the out-of-bounds case and decided to make runtime evaluation consistent with evaluation at creation-time error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found