Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to debug Turtle scripts (equivalent of "-x" flag in bash)?

I've recently started using Haskell Turtle library to replace some of my shell scripts.

Is there a way to somehow enable echoing of built in Turtle commands (like cd) ala set -x in bash scripts? I find it quite problematic to debug Turtle scripts in cases where many commands are executed and one of them fails with exception (like cp command with Exception:openBinaryFile: does not exist). Alternatively do you have some recommendation how to quickly isolate problems like these, so that I don't have to intersperse puStrLn/echo commands throughout my script?

like image 717
Jan Hrcek Avatar asked Sep 15 '15 10:09

Jan Hrcek


People also ask

Can you debug a bash script?

Bash provides extensive debugging features. The most common is to start up the subshell with the -x option, which will run the entire script in debug mode. Traces of each command plus its arguments are printed to standard output after the commands have been expanded but before they are executed.

What does X flag in bash do?

Invoking a Bash shell with the -x option causes each shell command to be printed before it is executed. This is especially useful for diagnosing problems with installation shell scripts. This option can only be used with Linux shell scripts, not with binary executables.

How do I debug a bash script in Vscode?

Open that in VS-code. First you will Cmd+Shift+P to go into command menu. Then you will type debug: Open launch. json, after this choose bash debug then select script from drop down (1st option).


1 Answers

Sadly, it is not possible, as turtle does not provide tracing. For example, mv is defined only with Haskell function (no shell call), so there is no way to print anything when it is ran:

mv :: MonadIO io => FilePath -> FilePath -> io ()
mv oldPath newPath = liftIO (Filesystem.rename oldPath newPath)

This limitation mentioned in the documentation, where the author recommends to take a look at Shelly, which is similar but provide extra features:

turtle is designed to be beginner-friendly, but as a result lacks certain features, like tracing commands. If you feel comfortable using turtle then you should also check out the Shelly library which provides similar functionality.

like image 113
madjar Avatar answered Nov 05 '22 06:11

madjar