How to debug quickly in phoenix/elixir? - debugging

As I am learning Elixir/Phoenix, I happen to run into an issue like this often.
The problem is that this comes from a dependency, so normally I do this:
open deps/something/.../thefile.ex
add some debug code like IO.inspect to see what params are being passed
stop server, recompile with mix deps.recompile something
check the documentation to see what types are expected to that function
compare the types and trace down the problem to my code
This works but I'd like to improve my process, I know I can use Iex to start a repl, but I'd like to get much faster in terms of:
having a repl inside of the error page itself started automatically (like in better_errors gem for Rails)
having a way to see what arguments went into that method without me digging around (could be solved by the former point)
being able to see a method's documentation quickly
Also any other tips are greatly appreciated.

Please open up an issue in Plug: https://github.com/elixir-lang/plug
You have some great suggestions, like accessing the docs and make the arguments explicit. I don't think we can provide a REPL at the place of error though.
EDIT 1: I went ahead and opened an issue here since I got excited about those improvements! :D
EDIT 2: I realize that I should probably have used a comment as this is not quite an answer (yet!)

Related

Update libraries after manual change

So I started working on my first open-source contribution in ruby. There I have the library I'm working on in the /lib/ folder. Now when I tried changing the code, my program (which uses the library) still uses the old code.
For example: Broke a function on purpose by deleting its end keyword (which should be causing an immediate crash), but it kept working perfectly after I did.
Another example was changing the code in such a way it should still work (mutating the output string) but it still returned the old string.
user~$ bin/ruby-hyphen -V "this is a test sentence"
this is a test sen-tence
Does anyone know if I have to tell the runtime to refresh it or something along those lines?
I found out why that happened. The file has a *.gemspec, which made it act as if it was a gem. To see the changes I needed to enter:
gem build *.gemspec
bundle exec rake install
Or, if you want to develop quicker: change everywhere you require it into a require_relative. That should also fix it. I hope this question helps someone in the future!

Mindmup installation procedure

How can I install mindmup as a standalone application using sinatra. Is there any proper documentation for that. I don't have experience with ruby. Please help.
The source code is available here
Note: this is a lazy hack, not the official way, etc...
Didn't work for me either. First it complained about $ which is just jquery, so i copied and pasted jquery into public/mm.js at the end. that solved that (not ideal, but who cares - technically, you should add another script dependency, etc...)
next, it tries to get external.js and external.css from static.mindmap.net which fails. All I did for this is simply look in mindmup.com with the google F12 thing, then find the external.css and external.js in the sources :) just dump these where the mm.js is.
It seems like the web.rb has the following
public_host = ENV['PUBLIC_HOST'] || 'http://static.mindmup.net'
so that's what was mucking everything up... change that to localhost:5000 and don't forget to get rid of the timestamp variable:
static_ts = '20150106142106'
turn into
static_ts = ''
Now it complains about portrait.png, some font awsome stuff etc... so we have to throw that in too.
and after all that, you still get an error, which really sucks...
so the code it's complaining in is actually the MM.main function! Which i assume is the primary function! It's some jquery thing where context is undefined... no clue how to go from here...

rom overflow and missing references in build for contiki example sky-shell

I have been trying to get the example sky-shell to build and am failing at it.
I have tried in contiki-2.6 and contiki-2.7. I had thought that it's possibly the compiler itself being inefficient or something so when trying in contiki-2.7 I made sure to try msp430-4.5.3, 4.6.3 and 4.7.0 (using the answer to this forum question to switch mspgcc versions: https://askubuntu.com/questions/187253/how-to-update-a-package-from-command-line-gcc-compiler).
None of this seemed to help. I also tried compiling with "SMALL=0" but this seemed to only increase the overflow.
I then tried commenting out any code in sky-upload.c (such as shell_netfile_init(), shell_rim_init() and shell_rim_netcmd_init()). This seemed to reduce the compilation enough so that it would get past the overflow in compilation, but now it says that it has missing references in function vuprintf to __udivmodsi4. I tried researching this issue and it seems that I may somehow be using a different version of gcc for part of the compilation than what I currently think (forum post here: http://sourceforge.net/p/mspgcc/mailman/mspgcc-users/thread/D45E6EE7-2771-41EC-9999-F773C6B22AA4#imag.fr/)
I feel like the example should work with none of the above mentioned init() calls commented out. It also seems that to ultimately get the example to work as intended (i.e. send ELF files over the air to a mote and then load them) I can't have the above mentioned init() calls commented out and may need even more code on top of what is provided in the example.
I realize that there are two main questions here and typically a post only deals with one at a time, but since they are muddled together I thought it best to post both issues (the overflow and the missing references).
Does anyone know what may be going wrong here? I am a novice when it comes to all things contiki so please add extra explanation wherever possible :).
Thanks

How do you remove functionality from a program in ruby?

You have some code you want to remove associated with an obsolete piece of functionality from a ruby project. How do ensure that you get rid of all of the code?
Some guidelines that usually help in refactoring ruby apply, but there are added challenges because having code that isn't being called by anything won't break any unit tests.
Update: Has anyone written anything that allows you to guess based on your version control history if there are commits where you have since deleted most, but not all, of the code and can point out the remaining code?
Current thoughts:
Identify the outermost part of the stack associated with the obsolete functionality: the binary script calling it, or the unit tests calling it.
Look for methods that are only called by methods associated with the obsolete functionality. I often use git grep for this.
In theory, running mutation testing and looking for code that used to be mutation resistant when the old test suite applied, but is now mutation prone might help. It only helps if your code was well-tested in the first place! (Or you can use code coverage tools such as rcov rather than mutation testing)
Running test suites will ensure you haven't removed anything you shouldn't have!
Using autotest can save you time if you're constantly running tests.
If your code was well-structured, it should be easier to find related methods that need to be removed.
Especially in a dynamically typed language, there is no easy way to do this. If you have unittests, thank the developer that wrote them because it will help you remove the code correctly. But you're basically SOL. Remove the code, if it breaks, put it back, figure out where it broke, attempt to work around it, and repeat.
Look at your code coverage. Any code which isn't covered may be part of the code you have left to remove (if any). (Just be sure you have removed you tests. =])

Avoiding Groovy/Grails internals while debugging in IntelliJ Idea

I'm using IntelliJ Idea 8.1.2 for Grails development. The dynamic nature of Groovy is giving me a hard time debugging my code: I keep ending up in the internals of Groovy/Grails, i.e. CachedMethod, ExpandoMetaClass or the like.
Is there a way for example to tell the Idea debugger to completely skip the Groovy/Grails internals while debugging and only make steps in my own code? I did notice that there is a configuration option named "Do not step into specific Groovy classes" in Debugger > Groovy but so far I've noticed no difference.
If not, what is your workaround or how do you cope with the situation? Any help would be greatly appreciated.
File->Settings->Debugger->Stepping
Do not step into the classes...
Yeah, I suffer with this annoyance, too, and I don't have a good solution. My workaround once I'm lost in Groovy/Grails code is just to figure out where I should be back in my code, set a break point there, and hit Continue.

Resources