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.

run_script continues after not a recognized command

See original GitHub issue

Filing as a separate issue, but related to #1185 and #1207. Currently run_script also suffers from not seeing the error caused by a command that doesn’t exist. A similar issue happens with unknown or incorrect arguments to a command. This would also occur in startup commands.

For example, with first_app.py, using this as a script

speak a
youdontsay b
speak --dummy 
speak c

does not stop execution on the second or third command and keeps running. Most users, I think, would expect a script to stop if it encounters an error situation like a command that doesn’t exist or badly formed arguments and would be surprised to see “c” printed.

When a command that does not exist is encountered now, onecmd() calls default() which just prints a message with perror(). But this means that neither runcmds_plus_hooks() nor _test_transcript() in transcript.py are aware that the failure situation has occurred and so they continue to the next command.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
crotwellcommented, Mar 1, 2022

Bash, for example, continues after an error because the next line can potentially use the exit code of the previous and do something appropriate on error. There is also set -e to tell bash to exit on the first error.

I am not suggesting cmd2 scripts should have sophisticated error handling features, keeping it simple is best for run_script. But I would humbly suggest that in the absence of error handling, “halt on first error” is the least bad strategy. Your call of course.

0reactions
chrysncommented, May 30, 2022

I agree @crotwell in that a set -e mode would be desirable for scripting (maybe enabled with set stop_script_on_error True). Ideally, that would halt script processing both on unknown commands and on commands that raise an exception.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"npm-run-all" Is Not Recognized As an Internal or External ...
You may just need to run the following command first (from the directory with the package.json file) npm install.
Read more >
Fix Problem Where Windows PowerShell Cannot Run Script ...
Error message when trying to run a script whose path contains spacesPermalink ... The term 'C:\My' is not recognized as the name of...
Read more >
5 Ways to Fix the "Not Recognized as an Internal or External ...
Here's how to fix that. fix not recognized as internal external command cmd. The Command Prompt in Windows is a handy utility.
Read more >
Fix for PowerShell Script cannot be loaded because running ...
This is due to the Windows PowerShell execution policy being set to prevent untrusted scripts which can affect your Windows client environment.
Read more >
runscript(1): script interpreter for minicom - Linux man page
runscript is a simple script interpreter that can be called from within the minicom communications program ... Runscript recognizes the following commands:.
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