I have created a .txt document using the “Log” activity to store the logs I create within the program. I’d like to append to this document the details of errors, similar to the way they appear in the console log with the activity “Console Log”, but I don’t know how to do that. I want to “capture” the error message because I don’t know what exactly goes wrong, so I don’t know what to say in the message. I’m not very experienced with JavaScript and I’m having trouble finding a way to show the exact error in the log. Does anybody know how I can do that in ElectroNeek?
Hi!
You can capture the error messages thrown by an activity using the red dot in the activity, without even using JavaScript or any other code.
You can connect the red dot of the activity from which you want to capture its error to a “Log” activity, and in that Log activity’s “Text” property, you can select “Save the previous step result”. This will write the error message as a new line in the log file. Here’s an example:
In this example, the “Copy file” activity is trying to copy a file that does not exist. So as you can see, we are getting an error in the Console (“ENOENT: no such file or directory, stat…”)
Now we add the following activity, connected not to the white dot (which would follow the regular, non-error flow), but to the red dot (which is only followed when errors happen on the activity). And we set it up like this:
Running this generates a text file called “test_log.txt” on the project folder, which now contains this:
If you would like to add some more text to that error, you can have an “Assign value to variable” activity inbetween the red dot of the original activity and the “Log” activity to save the error message to a variable (for example, “error_msg”). Like this:
Then, in the “Log” activity, you would use the “Calculate a value” option, and use the variable within the text. Like this:
That will produce the following content on the log file:
I also reccommend you check out the Help Center article for the “Log” activity (also called “Append to file”), which can be found here, for more details.
Hope this helps! Let me know if it does, or if you need me to clarify anything from this answer.
This is exactly what I was looking for. My brain completely ignored the “Save previous step result” option and I spent a lot of time researching about how to capture error messages using JavaScript. Thank you so much for the help!