Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch node crashing if property does not exist #109

Closed
colinl opened this issue Mar 29, 2023 · 5 comments
Closed

Switch node crashing if property does not exist #109

colinl opened this issue Mar 29, 2023 · 5 comments

Comments

@colinl
Copy link
Contributor

colinl commented Mar 29, 2023

If I configure a Switch node to test, for example, global.mcuTopics.analogue_0.topic for not null, or not empty, or in fact anything else, I think, then if global.mcuTopics does not exist, the s/w crashes with code such as

		onMessage: function (msg) {
			let value = globalContext.get("mcuTopics").analogue_0.topic;
			const result = [null, ];
			if (this.empty(value)) {
				result[0] = msg;
			}
			return result;
		},

at the line let value = ... with the message "cannot coerce undefined to object!"
The normal node-red does not crash, but instead then fails tests such as not empty and not null.

@phoddie
Copy link
Owner

phoddie commented Mar 29, 2023

Thanks for the report and example.

There's a straightforward fix for this in the code generator in nodered2mcu. That should be available later today from the Moddable SDK repository.

mkellner pushed a commit to Moddable-OpenSource/moddable that referenced this issue Mar 29, 2023
@colinl
Copy link
Contributor Author

colinl commented Mar 30, 2023

All working with the latest Modable SDK

@colinl colinl closed this as completed Mar 30, 2023
@phoddie
Copy link
Owner

phoddie commented Mar 30, 2023

Great, thanks for the quick confirmation.

@colinl
Copy link
Contributor Author

colinl commented Mar 30, 2023

The ironical thing is, that because it didn't work, I had to find an alternative solution, and actually ended up with a significantly more efficient flow which didn't need the Switch node at all :-)

@phoddie
Copy link
Owner

phoddie commented Mar 30, 2023

Very nice. Constraints can necessitate a more thoughtful solution. That's part of what's fun about working on microcontrollers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants