Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Just quickly – this is the general steps that I loosely follow for fixing bugs in Rails and other codebases that I don't fully understand (i.e. I didn't write the code myself):

1. Reproduce the issue: based on the reporter's comment, try to infer what the "buggy" behaviour is and attempt to reproduce it.

For Rails specifically, it means you need to get the code checked out and get comfortable running it locally. For Active Record and Action Controller bugs, you can use these templates as a starting point to create an isolated reproduction without making an entire app every time.

Sometimes this is not possible (the report is too vague, or you cannot reproduce it). In those cases, ask the OP for clarification and move on.

2. Is this "buggy" behaviour indeed a bug? Sometimes a lot bug report boils down to misunderstanding of the API, using the code in ways that the original author did not intend, or it's otherwise previously reported and closed as "won't fix" for various reasons. This is the part where the research skills you learned in school comes into play. It's not actually that different from, say, doing your research for an essay, you just have to map your skills to slightly different tools/problems.

Read the documentation. Understand the test cases. Get comfortable with using git blame (or the github blame view). Dig deep into the history of the method and figure out why it was added in the first place and for what purpose. Search the issue tracker. Read the previous PRs and issues that led to the code changes you are seeing. Study the commit messages. Ping the originally author (e.g. using @mentions on Github) if you are still unsure.

3. Once you are fairly certain that the reported behaviour is indeed a bug, you need to isolate the root cause. In some cases, after your research in step 2 you would already have a pretty good idea about this. In other cases, it's just like how you debug any other programs.

If you have a reproduction ready from step 1, this is going to be a lot easier. If not, consider starting by writing a failing test.Get a stack trace (e.g. "raise 'omg'"). Set breakpoints (or litter the code with puts statements). Basically you want to follow the input and trace it through the various steps and figure out where did it stop working the way you expect. Sometimes it's easier to do this top-down, sometimes it is easier to go from bottom-up (trace the output back to the input).

Another approach that works well for regressions (i.e. things that stopped working or works differently across releases) is to use git bisect to isolate the commit that broke the behaviour and try to relationship between the change and the bug.

4. If you did the previous step right, you should know how to fix the bug by now. Sometimes it is more difficult than simply reverting the offending change, perhaps because code around it and/or the overall architecture have changed significantly. Or perhaps because the offending commit was introduce to fix another bug, etc, and reverting it would negate the primary purpose of the commit. In those cases, you have to get creative and explore the different ways you can fix the bug. You can always document your findings up to this point and ask someone on github if you're unsure.

5. Once you figured out how to fix the bug, then you have to polish your patch. This means following the guidelines of the project and work it to the level that's acceptable for the project. In Rails, this means that you must write a regression test and follow the various guidelines we have[1]. CHANGELOGs, rebase, squash, commit messages, etc. Whatever it takes to make the project's maintainers happy. Once you did it once and figured out the tools, this would quickly turn into a brainless mechanical task.

6. Submit the patch. This is one of the most important step that everyone overlooks. As a responsible maintainer, I cannot simply accept/merge your changes because you claim that it fixed a bug and you have a passing test to go with it. I need to understand the problem and the code enough to help evaluate if you fix is good – whether it causes other unintended effects elsewhere, could it be simplified, is it going to introduce performance problems, etc. Make that easy for me. Explain the problem. Explain what the code is supposed to do and where you got that from. Explain why you chose to fix it this way. Do you have any doubts/concerns about this that you'd like me to help you figure out? Is there anything else I should be aware of?

If one or more of these things are missing, I'd have to spend time understanding them before I can evaluate your patch. If I don't have time to do that (which is usually the case), I might just have to move on to other stuff and park this for "later". Which is a shame, because you already did all the work to learn about these things. (Of course, I can't just take your words for it either. But at least make it easy for me to verify your findings. Linking the commits/issues/docs in the pull request and/or commit message goes a long way.)

7. Rework your patch. Sometimes you get questions/feedback from the reviewers. Address the concerns either by explaining your motivations or fixing the code as suggested. Rinse and repeat.

* * *

At the end of the day, this is just remapping your problem solving skills (which you are obviously very good at, since you are a programmer :) to the right domain and tools. I hope this helps!

If you are looking for things to do, I suggest that you digest what I just typed a bit and try to incorporate some of the ideas here into the contributing to rails guide[1]. Since you still have questions after reading that, obviously there are room for improvement :) Doing that will help save future wasd time as well as giving you a chance to practice steps 3-7.

[1] http://edgeguides.rubyonrails.org/contributing_to_ruby_on_ra...



Oops, I forgot to link the templates in step 1, here you go: https://github.com/rails/rails/tree/master/guides/bug_report...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: