Skip to content

Commit

Permalink
Fix the **stupidest bug ever**
Browse files Browse the repository at this point in the history
I don't believe it, I spent 4h debugging this, as it was working
perfectly fine on my local machine (both on Windows & Ubuntu WSL2), but
it kept failing for all Python versions on GitHub Actions, but only for
Windows.

The root cause turned out to be very simple: CRLF XD

In Git there is core.autocrlf option which handles it. In my Windows
dotfiles a long time ago I've changed it to `input` which is not the
default for this platform.

Git on Windows in GitHub Action uses the default option `true`, which
means that files are always converted to CRLF which is `\r\n`. And that
caused the regex for zettel title to stop matching which caused test
failures.

And I introduced this bug in a huge commit with almost 500 lines of diff
(major refactors FTW) which was the main cause why it took so long to
debug. The problematic commit is:

e028160

I located it by using a bisect (i.e. binary search) method. But because
it was failing only in the CI, I did it manually in ~5 iterations. So
it was a bit annoying, but still quite quick.

Later, based on the newest main, I reverted the problematic commit
resolving a ton of merge conflicts and fixing unit tests, so they work
locally and on the pipeline.

Having a stable version, I created a new branch from it, and started the
investigation. I applied small commits to this branch, making it more
and more like the newest main. It took the most time because my reverted
commit still was huge I didn't have any clue what was the reason.

Lessons learned:

- Small commits FTW
- If something fails *only on Windows*, CRLF is a good suspect
- Read the logs carefully!

**The most important one**

Before making the revert commit approach, I tried to analyze what's
going on in the CI. But if something fails only in CI, debugging is
pretty much impossible. I should ask a question why it fails only in
CI, and try to fail it somewhere else, where I can attach a debugger.

And the worst thing: in the pipeline I still did some debugging with
logging AND NOW I SEE THE '\r' IN THE LOG!!!

DEBUG    root:zettel.py:150 Got zettel: 'Zettel(title='# Zet test entry\r\n', id='20211016205158', tags=('another-tag', 'tag-after-two-spaces', 'test-tag'), path=WindowsPath('testing/zet/zettels/20211016205158/README.md'))'

https://github.com/tpwo/pyzet/actions/runs/6789721036/job/18457559890

Unfortunately, I didn't notice it during the log inspection, and that's how
4 hours were wasted. What a lesson!
  • Loading branch information
tpwo committed Nov 7, 2023
1 parent 46ebafd commit 49cfe9e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/pyzet/zettel.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def get(path: Path) -> Zettel:

return Zettel(
id=id_,
title=get_markdown_title(title_line, id_),
title=get_markdown_title(title_line.strip(), id_),
path=path,
tags=tags,
)
Expand Down

0 comments on commit 49cfe9e

Please sign in to comment.