Force ruby to hide backtrace on exception - rakefile

I do some usual tasks with Rakefile, such as compilation, linking, etc.
When compilation fails ruby shows full backtrace in which task error happen, but it's really useless for me, even more: this backtrace hides compilation errors.
$ rake
mkdir -p build
llvm-as source/repl.ll -o build/repl.bc
llvm-as: source/repl.ll:6:22: error: expected value token
call i32 #fputc(i8 'x', i32 0)
^
rake aborted!
Command failed with status (1): [llvm-as source/repl.ll -o build/repl.bc...]
/usr/local/lib/ruby/1.9.1/rake.rb:993:in `block in sh'
/usr/local/lib/ruby/1.9.1/rake.rb:1008:in `call'
/usr/local/lib/ruby/1.9.1/rake.rb:1008:in `sh'
/usr/local/lib/ruby/1.9.1/rake.rb:1092:in `sh'
...
How to hide all after "rake aborted!" ?

It seems that you are using the "sh" command in the rake task to start the compiler. In that case you should catch a RuntimeError, in order to get this error. Something like this:
task "foo" do
begin
sh "bar"
rescue RuntimeError => e
puts e.message
exit(1)
end
end

Related

Swift 3.0 source code build error

These days I was trying to compile Swift 3.0 on macOS followed by the instruction which is on GitHub step by step, when I run utils/build-script -x shell, got a failue like this:
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution CMake\ Rules /Users/knight/githubRepo/swift-source/build/Xcode-DebugAssert/swift-macosx-x86_64/stdlib/public/core/Swift.build/Debug/add_custom_command_target-004471a8febeaad1237722247e0e4ace-Swift.o.build/Script-627C6DA99FFD4D7E8932585C.sh
(1 failure)
utils/build-script: fatal error: command terminated with a non-zero exit status 65, aborting
command line result
Does anybody met this problem before? Would you please show me your resolution?

"cpanm PHP" fails

What should I change in order to install the module? php is 5.3.3 withyum install php-devel in place.
PHP.c: In function ‘PHP_set_php_input’:
PHP.c:818: warning: passing argument 2 of ‘Perl_sv_2pv_flags’ from incompatible pointer type
/home/mpapec/.plenv/versions/5.20.0/lib/perl5/5.20.0/x86_64-linux/CORE/proto.h:3931: note: expected ‘STRLEN * const’ but argument is of type ‘int *’
cc -c -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -Wall -O2 -DVERSION=\"0.15\" -DXS_VERSION=\"0.15\" -fPIC "-I/home/mpapec/.plenv/versions/5.20.0/lib/perl5/5.20.0/x86_64-linux/CORE" array.c
In file included from /usr/include/php/main/php.h:33,
from /usr/include/php/sapi/embed/php_embed.h:23,
from PHP.h:14,
from array.c:9:
/usr/include/php/main/php_config.h:2417:1: warning: "_GNU_SOURCE" redefined
In file included from /home/mpapec/.plenv/versions/5.20.0/lib/perl5/5.20.0/x86_64-linux/CORE/perl.h:28,
from PHP.h:9,
from array.c:9:
/home/mpapec/.plenv/versions/5.20.0/lib/perl5/5.20.0/x86_64-linux/CORE/config.h:1825:1: warning: this is the location of the previous definition
rm -f blib/arch/auto/PHP/PHP.so
cc -shared -O2 -L/usr/local/lib -fstack-protector PHP.o array.o -o blib/arch/auto/PHP/PHP.so \
\
chmod 755 blib/arch/auto/PHP/PHP.so
"/home/mpapec/.plenv/versions/5.20.0/bin/perl5.20.0" -MExtUtils::Command::MM -e 'cp_nonempty' -- PHP.bs blib/arch/auto/PHP/PHP.bs 644
Manifying 1 pod document
Running Mkbootstrap for PHP ()
chmod 644 "PHP.bs"
PERL_DL_NONLAZY=1 "/home/mpapec/.plenv/versions/5.20.0/bin/perl5.20.0" "-Iblib/lib" "-Iblib/arch" test.pl
1..79
not ok 1 - use_ok PHP
# Failed test 'use_ok PHP'
# at test.pl line 11.
not ok 2 - require PHP;
# Failed test 'require PHP;'
# at test.pl line 18.
# Tried to require 'PHP'.
# Error: Attempt to reload PHP.pm aborted.
# Compilation failed in require at (eval 6) line 2.
not ok 3 - eval
# Failed test 'eval'
# at test.pl line 49.
Module PHP failed to load at blib/lib/PHP.pm line 80.
Module PHP failed to load at blib/lib/PHP.pm line 80.
END failed--call queue aborted at test.pl line 50.
# Looks like you planned 79 tests but ran 3.
# Looks like you failed 3 tests of 3 run.
# Looks like your test exited with 22 just after 3.
make: *** [test_dynamic] Error 22
-> FAIL Installing PHP failed. See /home/mpapec/.cpanm/work/1440522239.12833/build.log for details. Retry with --force to force install it.
(
PHP is kind of fragile. It probably won't work out of the box with your system php installation, and may have trouble with 64-bit or multi-threaded versions of perl.
I have only ever gotten it to work on Linux. The latest version I have tried to use is 5.3.8 (back in 2013), though I remember things going smoothly from 5.2.x to 5.3.8.
I always build php from source, with this configuration:
./configure --enable-embed --with-zlib --with-openssl --with-mysql \
--with-libdir=lib/i386-linux-gnu
--enable-embed is absolutely required, as the pod mentions, to build a PHP interpreter with the SAPI extension, and which then allows perl to manipulate the PHP interpreter through XS code. The other extensions were for other requirements of my project; they may be optional, but I haven't experimented with building the PHP interpreter or the PHP module with any other configuration. The pod also says to never use the --with-apxs argument, which I was never tempted to do anyway.
The build process of the PHP module will look for and require a program called php-config. You may need to hack your $PATH, if only during the build process, so that the PHP module runs the correct php-config. After that the module will know where to look for the rest of your php installation.
I had fun working with this module for a while (writing a Catalyst and then a Mojolicious wrapper around WordPress), but it has fallen into disrepair and disrepute. Share whatever you learn trying to build it and we'll put it in the docs, making this module that much easier to use.

How can I capture / log a fatal error in Swift?

For example, fatal error: unexpectedly found nil while unwrapping an Optional value. Regardless of the cause, can this data be captured? Is this stderr or something else?
Edit: I found a reference at http://swiftdoc.org/func/fatalError/ that says the function (which I'm assuming is indeed what Swift is internally calling) "Unconditionally print a message and stop execution.". So perhaps there's nothing left to do but get ahold of the remote crash report via TestFlight crash reports or actually having the device handy.
I'm able to log all uncaught exceptions via NSSetUncaughtExceptionHandler in main.swift, and we have good logging going on in other parts of our app wherever bad (but possible) errors can occur. I was hoping to also log these fatal errors so that our logs show a more complete picture of crashes occuring on remote testing devices.
Certain errors will go to stderr. Here is a simple example:
$ cat tryit
#! /usr/bin/env swift
println ("foo")
precondition (false, "bar")
$ ./tryit 2> /tmp/error 1> /tmp/noterror
Illegal instruction: 4
$ cat /tmp/noterror
$ cat /tmp/error
precondition failed: bar: file ./tryit, line 4
0 swift 0x000000010f7faa18 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x000000010f7faef4 SignalHandler(int) + 452
...
If you remove the precondition, then the results go to stdout:
$ cat tryit
#! /usr/bin/env swift
println ("foo")
$ ./tryit 2> /tmp/error 1> /tmp/noterror
$ cat /tmp/noterror
foo
$ cat /tmp/error

rake neo4j:create error rake aborted

>sudo rake neo4j:create --trace [ 6:18PM]
rake aborted!
Don't know how to build task 'neo4j:create'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task_manager.rb:49:in []'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:115:ininvoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:ineach'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:instandard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:88:in top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:66:inrun'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:63:inrun'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/bin/rake:33
/usr/bin/rake:19:in `load'
/usr/bin/rake:19
What may be the probable reason for this error. I am following the maxdemarzi introduction to neo4j and d3.js.
I will be thankful if some one can suggest the solution
https://github.com/maxdemarzi/d3_js_intro
I've updated the project so it works now. Please run:
git pull # Get the latest code
bundle install # Update the project gems
rake neo4j:reset_yes_i_am_sure # Reset the Neo4j Server
rake neo4j:create
Ping me if you still have trouble.
Regards,
Max

Erlang boss_db hello world?

Recently I tried to install and run a demo of boss_db ORM for Erlang.
Here is what I did:
clone the repository
cd boss_db/
rebar get-deps
put a simple mydb.erl file into src/:
-module(mydb).
-compile(export_all).
start() ->
DBOptions = [{adapter, pgsql},
{db_host, "localhost"},
{db_port, 5432},
{db_username, "postgres"},
{db_password, "mypass"},
{cache_enable, false},
{cache_exp_time, 0}],
boss_db:start(DBOptions).
rebar compile
cd ebin/
run erl
mydb:start()
Here is what I get:
** exception exit: shutdown
Whatam I doing wrong here? How is it supposed to be run?
P.S. I tried to run application:start(boss_db) as well, but the result is the same.
P.P.S. I have read the documentation twice, but I still have no idea how to run the whole thing.
You are not adding dependencies to the code path. That's why an exception is thrown when they are not found. Don't cd into ebin and erl. Instead run
erl -pa ebin -pa deps/*/ebin
from the current directory.
Btw this is not a good way to do this kind of stuff. Instead create a new empty app using rebar. Add boss_db as a dependency to your app in rebar.config. Put your own source files under src. And then
rebar get-deps compile
erl -pa ebin -pa deps/*/ebin
git clone git://github.com/evanmiller/boss_db.git
cd boss_db/
rebar get-deps
emacs src/mydb.erl
rebar compile
erl -pa ./ebin ./deps/*/ebin
These steps worked for me. code:is_loaded() will not work right after you run erl. Only when the module is invoked, the code is loaded.
I do get an application shutdown, but it is because the code is trying to connect to a Postgres DB and can't connect to it.
Erlang R15B02 (erts-5.9.2) [source] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.2 (abort with ^G)
1> mydb:start().
** exception exit: shutdown
=ERROR REPORT==== 9-Oct-2012::12:13:07 ===
** Generic server <0.35.0> terminating
** Last message in was {'EXIT',<0.34.0>,
{{badmatch,
{error,
{{badmatch,
{error,
{{badmatch,{error,econnrefused}},
[{pgsql_sock,init,1,
[{file,"src/pgsql_sock.erl"},{line,51}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,304}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}}},
[{boss_db_controller,init,1,
[{file,"src/boss_db_controller.erl"},{line,31}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,304}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}}},
[{poolboy,new_worker,2,
[{file,"src/poolboy.erl"},{line,348}]},
{poolboy,prepopulate,4,
[{file,"src/poolboy.erl"},{line,370}]},
{poolboy,init,2,
[{file,"src/poolboy.erl"},{line,74}]},
{gen_fsm,init_it,6,
[{file,"gen_fsm.erl"},{line,361}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}}
** When Server state == {state,
{<0.35.0>,poolboy_sup},
simple_one_for_one,
[{child,undefined,boss_db_controller,
{boss_db_controller,start_link,
[[{size,5},
{max_overflow,10},
{adapter,pgsql},
{db_host,"localhost"},
{db_port,5432},
{db_username,"postgres"},
{db_password,"mypass"},
{cache_enable,false},
{cache_exp_time,0}]]},
temporary,brutal_kill,worker,
[boss_db_controller]}],
{set,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],
[],[]}}},
0,1,[],poolboy_sup,
{boss_db_controller,
[{size,5},
{max_overflow,10},
{adapter,pgsql},
{db_host,"localhost"},
{db_port,5432},
{db_username,"postgres"},
{db_password,"mypass"},
{cache_enable,false},
{cache_exp_time,0}]}}
** Reason for termination ==
** {{badmatch,
{error,
{{badmatch,
{error,
{{badmatch,{error,econnrefused}},
[{pgsql_sock,init,1,
[{file,"src/pgsql_sock.erl"},{line,51}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,304}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}}},
[{boss_db_controller,init,1,
[{file,"src/boss_db_controller.erl"},{line,31}]},
{gen_server,init_it,6,[{file,"gen_server.erl"},{line,304}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}}},
[{poolboy,new_worker,2,[{file,"src/poolboy.erl"},{line,348}]},
{poolboy,prepopulate,4,[{file,"src/poolboy.erl"},{line,370}]},
{poolboy,init,2,[{file,"src/poolboy.erl"},{line,74}]},
{gen_fsm,init_it,6,[{file,"gen_fsm.erl"},{line,361}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]}