Read/Write Tags/Groups should be more await friendly by allowing const [ error, data ] = PLC.readTag( tag )
Current Behavior
You can currently await any of these functions but if an error happens, it throws an uncaught promise error which are pretty annoying to track down. The workaround is to write a wrapper for each function that returns a promise and catch errors yourself which makes the current level of support for await pointless.
Expected Behavior
You should be able to handle all errors like so:
const [ error, data ] = PLC.readTag( tag )
if ( error ) {
// handle the error, log error, break you current block, etc
}
Another option could be to pass an error callback but... or an options object to control return structure
Possible Solution (Optional)
Each of these functions should contain a then and a catch and both should return something and not cause unhandled promise rejection errors. Returning [ false, data ] could be a breaking change however so a callback could be added to be executed on the catch block.
I currently use await-to-js to "awaitify" these functions.
Context
Trying to use async await much more than I used to and encountering unexpected issues or forgetting to use helper functions.
Steps to Reproduce (for bugs only)
Use any await example from the README
Try it on a tag that doesn't exist or throws some other error
Read/Write Tags/Groups should be more await friendly by allowing
const [ error, data ] = PLC.readTag( tag )
Current Behavior
You can currently await any of these functions but if an error happens, it throws an uncaught promise error which are pretty annoying to track down. The workaround is to write a wrapper for each function that returns a promise and catch errors yourself which makes the current level of support for await pointless.
Expected Behavior
You should be able to handle all errors like so:
Another option could be to pass an error callback but... or an options object to control return structure
Possible Solution (Optional)
Each of these functions should contain a
then
and acatch
and both should return something and not cause unhandled promise rejection errors. Returning[ false, data ]
could be a breaking change however so a callback could be added to be executed on thecatch
block.I currently use await-to-js to "awaitify" these functions.
Context
Trying to use async await much more than I used to and encountering unexpected issues or forgetting to use helper functions.
Steps to Reproduce (for bugs only)
Your Environment
npm list
- e.g. 1.0.6):node --version
- e.g. 9.8.0):