Tag Archives: debug

Rubber Duck Debugging

There is a bit of dev folklore about a developer who had the experience of people coming to ask for help with problems they had encountered. What kept happening was  that they would stop midway through explaining the problem and walk away with a solution. All without the dev saying a thing.

After this happened a few times, the dev realized his participation in the process might not be required. To test this theory, he put a rubber duck on his desk.

The rule was, if you wanted to ask a question, you first had to explain the problem to the duck. Amazingly, explaining the problem to the duck had the same success rate as explaining the problem to the dev.

This practice has become known as “Rubber Duck Debugging.”

I’m not saying I’ve ever engaged in rubber duck debugging, but just yesterday I stopped partway through entering a support ticket and implemented the solution without any involvement from the support team….

Troubleshooting puppeteer in WSL2

I’m working on a small project to generate image files from HTML using a web browser. This is something I’ve toyed with for a while, but never really dug into canvas far enough. Once I discovered the puppeteer package for node, the dream seemed suddenly within reach.

Everything was going along fine, until I got to the point of actually trying to launch the headless browser. Then my program started crashing with the message:

(node:4279) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
/mnt/c/Users/blair/git/image-gen/node_modules/puppeteer/.local-chromium/linux-818858/chrome-linux/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

The message included a link to a troubleshooting guide, which did mention some tips for Windows, but that was the Windows GUI environment and I’m using Ubuntu 20.04, running under the Windows Subsystem for Linux (WSL2). That meant it was either fix it myself, fire up a VM, or install node under Windows (which would mean losing the node version manager tool).

One of my main reasons for doing Node development in Linux is the ability to use nvm. A VM is much too heavy a solution for my tastes, so I wanted to see if I could get it working. And off to Google I went.

Searching for the error message is my usual first step, but although it turned up plenty of other people having problems (plus a few open GitHub issues from several years ago), it didn’t offer any solutions. Finally, a search for “puppeter wsl2 libnss3.so” led to a comment on an issue from last June where someone got it running by installing a bunch of packages manually.

0ne of the nice things about WSL is if you break your installation badly, it’s fairly trivial to remove it and reinstall a new copy. So it was fairly low risk to try installing the missing pieces to see if I could get it to work.

The error message even gave me a starting point: “error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory.”

There’s a page at https://packages.ubuntu.com/ which allows you to search for which package a library comes from. I started by putting libnss3 in the keyword field and specifying focal (aka “20.04”) as the distribution, and began the iterative process of looking up the installing the missing packages, trying my program again, and then looking up the next failed package. Happily, all it took was a half-dozen tries before my script started working again.

Here’s the list:

libnss3
libatk-adaptor
libcups2
libxkbcommon0
libgtk-3-0
libgbm1

Full-disclosure: midway through, it occurred to me that the reason the packages were missing might be because WSL isn’t a GUI environment and therefore doesn’t have a browser installed. Running sudo apt install -y chromium-browser didn’t solve the problem, but it is possible that this installed some additional packages which I was then able to avoid installing manually.

Now to see if I can get it to render a page. ?

Rubber Duck Debugging

A co-worker asked me a question relating to how our software works. As soon as he finished framing the question, and before I could respond, he finished with, “Oh, of course…” and answered his own question. I don’t there’s a techie alive who hasn’t experienced this phenomenon from one side or the other.

There’s a practice called “Rubber Duck Debugging.” In a nutshell, when you have a problem, you explain the problem to the duck so that you can figure it out.

Coincidentally, there’s a rubber duck on top of a bookcase next to my desk. This co-worker and I had gone through similar debugging episodes before, so I told him that going forward, he should first talk to the duck. This particular co-worker works remotely most of the week, so I told him we’d have to find a way he could talk to the duck online.

Sure enough, someone else had already thought of this. Five minutes later, I found the Cyberduck – an Eliza-based chatbot.

git error: Permission to user-B/repo.git denied to user-A

I have two GitHub accounts: UserA and UserB. Over time I’ve been switching to working with UserB, but the switchover was a bit difficult.

I created a test repository on GitHub at https://github.com/UserB/test

On the local system, from the command prompt

cd \git
git clone https://UserB@github.com/UserB/test
cd test
# make some changes to README.md, add a new foo.txt
git add *
git commit -m "Banana!" # In real life, you'll probably want a more useful comment.

And that’s where the train went off the rails…

C:\git\test>git push
remote: Permission to UserB/test.git denied to UserA.
fatal: unable to access 'https://UserB@github.com/UserB/test/': The requested URL returned error: 403

So git’s saying that even though I expressly got this as UserB, it still thinks I’m UserA

Google came back with lots of stuff about making sure you have the right SSH key (apparently the cool kids do everything over SSH).

A few search results make reference to the Windows Credential Manager. Apparently the Windows version of Git hooks into that somehow. What’s the Windows Credential Manager? Well, from the name, it sounds like something that might be used for storing userids and passwords.

OK, so how do I invoke it? Dunno. Let’s try the search box on the START menu. Aha! Two entries. One for “Credential Manager” and one for “Manage Windows Credentials.”

So let’s try the first one. Hey! This looks promising:

About halfway down the list, there’s one labeled “git:https://github.com” Let’s expand that.

Oh, looky there! Username and password.

Now what I did was to remove the entry and then push again. I was prompted to enter a userid and password. I still had to type the password at the command prompt, but IT STUCK.

C:\git\test>git push
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 304 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/UserB/test
5e74c47..cf2ca13 master -> master

I probably could have clicked “Edit” and changed the userid and password, and just kept going, but I didn’t notice the “Edit” right away.

It looks as though you might actually be able to have multiple entries for git:https://github.com, but I haven’t tried that yet.

(Public domain photo from PublicDomainPictures.net)