Monday 15 October 2018

Hacktoberfest Second Pull Request

In my second pull request I fixed a bug in Filer.

How I fixed a bug

  1. I was writing a test for rename() when oldPath==newPath (You can see a discussion here). It was expected that function will successfully rename a file, but it failed. We came to the conclusion that function implementation has a bug. Bug was assigned to me and I started working on it.
  2. I went to the implementation file, found rename() and tried to understand how it works.
  3. I found out that find_node() is called and went to it.
  4. In find_node() another function is called, in another function one more function is called, etc. There was a long way to find a mistake, a lot of functions was called. This long process is not interesting to read about, so I will not write about all ifs and function calls.
  5. Finally, check_if_new_file_exists() is called. It has this "if" inside:
if(_(newDirectoryData).has(newname)) { callback(new Errors.EEXIST('newpath resolves to an existing file', newname)); }
If a file with the name we want to rename a file to already exists, callback with an error is called. I removed this if statement and spaces in the else statement that is following this "if". After these changes my test with oldPath==newPath passed (all other tests also passed).

Fixing bugs in your own code is sometimes difficult, even though you know how your code works. But fixing bugs in someone else's code is always more difficult: you have to find out how it works. Different styling and programming techniques slow down debugging. So, I think it would be more rational if a person that wrote a code fixed bugs himself and other people just wrote tests.

No comments:

Post a Comment