I am developing a Clojure program from a REPL in Cursive. I would like to see stack traces with the error messages. By default it seems that only the error message is output.
If I 'Edit Configurations...' I can see that the REPL is a 'Clojure REPL' and that 'Use clojure.main in normal JVM process' is specified. I believe this is a fairly standard REPL setup with Cursive.
All the clojure source files are in the user namespace, and there is nothing special about the project.clj lein project file.
Currently if I want to see a stack trace I need to run the program like this:
(use 'clojure.stacktrace)
(x)
(print-stack-trace *e 30)
Here (x) is running the program that is crashing. These steps work from both the command line (starting off with lein repl) and from within the Cursive REPL.
Are there some setup steps that I can do so that stack traces are always shown with error messages and so (use 'clojure.stacktrace) and (print-stack-trace *e 30) become superfluous?
You can add a keymap to "Print last exception" menu item.
Open the settings with ⌘, then access Keymap > Main Menu > Tools > REPL.
Double click "Print last exception" and choose a shortcut.
Related
Is there a way I can make emacs compile and run my code in an external console window with the command M-x compile (what I mean by external console window is that I want it to run my code in a new console window like it does when I run my C++ code in visual studio).
I want emacs to automatically open up a new console window and run the executable after M-x compile like this:
Normally with Emacs, when you want some obscure (i.e. some simple, or special to your use case) automation, you just write a command, which does what you want.
Here is such an example. Following Elisp code calls a function and-run, when compilation is finished (through using hook compilation-finish-functions).
(defun and-run (&rest _)
"run after comilation, an not elaborated example function"
(interactive)
(let ((exe "./test.out")
(prevent-closing (concat "echo \"Press Enter to continue\"" ";"
"read"))
(terminal "xterm -e"))
(when (file-exists-p exe)
(let ((my-command (concat exe ";" prevent-closing)))
(shell-command (format "%s %s" terminal (shell-quote-argument my-command)))))))
(add-hook 'compilation-finish-functions #'and-run)
Since I'm no Windows user you have to make some small adaptions to this function, in order to be able to run it on Windows.
Note: there is also a compilation-start-hook, if you e.g. want to compare file-modification times of your exe.
So when I start the cloure web application with the command lein ring server, there are 2 processed that get started.
The first process is clojur.main that then runs the main web application. The jvm options
:jvm-opts ["-Xmx128m" "-server"]
for ring work to control the memory for the web application. The issue is that the clojure.main -m leingen.core.main allocates 300+ MB of heap space. (see screenshot 32)
well never mind
apparently I should run
lein trampoline ring server
This way leingen gets out of the way , saving memory
The other way is to create a uberjar:
> lein clean
> lein uberjar
Compiling demo.hello
Compiling demo.numbers
Created /home/alan/expr/demo-horizon/target/demo-horizon-0.1.0-SNAPSHOT.jar
Created /home/alan/expr/demo-horizon/target/demo-horizon-0.1.0-SNAPSHOT-standalone.jar
You normally always want to use the xxx-standalone.jar version.
Then you start the process using plain java w/o any lein at all:
java -jar /home/alan/expr/demo-horizon/target/demo-horizon-0.1.0-SNAPSHOT-standalone.jar
and you can add any flags like -Xmx4g or whatever else you like.
Update
I always run lein clean before creating a uberjar. This is the default behavior, but can be disabled by setting :auto-clean false in project.clj. According the the Sample project.clj:
; By default Leiningen will run a clean before creating jars to prevent
; undeclared AOT from leaking to downstream consumers; this disables
; that behaviour.
:auto-clean false
I cannot see why starting with a dirty build would ever be a good idea, which is why I always manually run lein clean first (just in case :auto-clean has been disabled).
You need to set :jvm-opts in your project.clj. e.g.
:jvm-opts ["-Xmx1g" "-server"]
See also this answer
According to Microsoft, "If [the system] cannot locate the DLL, the system terminates the process and displays a dialog box that reports the error. " This is the result I get when I run my application outside of the command line, but I do not get the same system error when I run the application from a shell environment such as command prompt or powershell.
Is there a way to show the same error message when the application is run from a command line interface?
https://msdn.microsoft.com/en-us/library/aa271571(v=vs.60).aspx
SetErrorMode(GetErrorMode() & ~SEM_FAILCRITICALERRORS);
but I don't think you want to do this, as you do not know in which environment the user will run your application.
It is usually now a good idea to popup a dialogbox in e.g. a service environment.
What is the problem with examining the error code of whatever is failing e.g. LoadLibrary() and reacting to this error?
I'm using Tortoise SVN, and TortoisePlink for remote ssh connections.
From time to time TortoisePlink is displaying errors like:
---------------------------
TortoisePlink Fatal Error
---------------------------
Network error: Software caused connection abort
---------------------------
OK
---------------------------
And they appears as messagebox and needs to be clicked by end-user.
I have tried to suppress messagebox by using -batch from command line, but problem still can be reproduced. For me it's sufficient if I'll disable messagebox prompting and print for example in command line same information - since my batch will retry later on again automatically.
Does there exists such software which can override default windows behavior and print in console window whatever is displayed in message box.
I guess in simplest terms such command line tool can be easily created, using for example
http://www.codeproject.com/Articles/44326/MinHook-The-Minimalistic-x-x-API-Hooking-Libra
and override MessageBoxA / MessageBoxW - but have anyone done this kind of thing ?
I think you're going about this the wrong way. Instead of trying to suppress the dialog boxes that TortoisePlink is showing, use the original Plink. TortoisePlink is a fork of Plink to explicitly show message boxes and not print anything on a command line, because it's designed for an UI app and not for console apps.
And if you really only want to use svn from a batch file, don't use TortoiseSVN but the original svn command line client (can be installed with the TSVN installer as well) and use the 'svn' command from the command line.
TortoisePLink.exe is targetted for end-user - so it's intended to display message boxes, however - there also exists a command line version of PLink.exe, and it can be downloaded from here:
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Please notice that "TortoiseSVN" > "Settings" > "Network" > "SSH Client" should use TortoisePLink.exe - errors will be displayed to end-user.
For following file however -
%appdata%\Subversion\
file ‘config’:
In section [tunnels]
Add line like this:
ssh = Plink.exe -l <your login> -pw <password>
You should use command line version of PLink.exe (that is also displaying command prompt when launched).
It's easier to save PLink.exe next with TortoisePLink.exe, that is into
C:\Program Files\TortoiseSVN\bin.
I have tried to make a command line tool for supressing messageboxes, but it's useless for TortoisePLink.exe (Haven't debugged what is the problem), but in case if you're interested (Have other means to use it):
https://sourceforge.net/p/diagnostic/svn/HEAD/tree/Tools/msgboxSupress/
msSupress.cpp is compiled into .dll and it uses minimalistic hook for windows to disable MessageBoxA and MessageBoxW - actually they will be printed to console or redirected to file.
msSupressExe.cpp is compiled into .exe and it starts process in suspended mode, replaces .exe's entry point with EB FE (jump short into itself), waits until that address is reached, injects .dll and .dll will hook new process.
I have tested only on 64-bit platform - I suspect that command being executed must match same platform as as msSupress.exe.
So typically TortoisePlink.exe will display messagebox - but when executed like this:
mbSupress.exe "C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe"
Same stuff as shown over message box will be displayed in console.
I think this solution is good prototype for further virus or trojan construction - using technique like this will allow to intercept even keyboard presses on any application - but I now made a command line utility, not a virus.
How do I give commands to run before starting gdb debugging in Eclipse ?
Actually I want to execute few scripts that set environment variables (export vars) and execute a bunch of other programs before gdb process is launched from eclipse to debug my program.
I tried doing the following in debugger tab option:
<command> && <path-to-gdb-executable>
But I got the error that eclipse cannot execute gdb as given in above statement.
Please help - I actually want to execute a script called "before-launch-commands.sh" before debugging is started by gdb. I am trying to execute a cpp program under eclipse kepler.
Thanks.
The Eclipse Debug Configurations can already setup environment variables for you. I'm going to assume that that isn't sufficient, or you'd have already done it.
The first thing to do is create a new script, wrapped-gdb.sh:
#!/bin/sh
# Export any variables we need.
# Note that '.' (dot) is like an "include" statement.
. /path/to/before-launch-commands.sh
# Run GDB using the parameters passed in
exec /path/to/gdb "$#"
Next, set that script executable:
chmod +x /path/to/wrapped-gdb.sh
Finally, go to the Debugger tab in the debug configuration dialog, and in the box marked "GDB Debugger" enter /path/to/wrapped-gdb.sh.
When you launch your debug session it should now Do The Right Thing.