A First World Car problem

Today I ran into a little trouble with my car navigation. I’m driving home using the navigation (pardon me, I just moved to the Seattle so I still needed help getting around), and I heard the GPS voice going “…t..a…ke exit 10”. Normally, my car would say in advance: “in a quarter of a mile, take exit 10”. So I thought to myself, this is odd. A few minutes later, it did it again, this time it skipped so badly I almost missed a different exit.

I was struck with disappointment because here I was, just bought the brand new car 6 months ago, and now it already showed its first problem. This car I also have the adaptive cruise control. For those of you who don’t know, this is a new feature in cars where it adjusts its speed to the car in front so you don’t have to keep pressing gas and brake when you cruise on the highway. Now I feel unsafe because the navigation voice is acting up, what if next time my cruise control doesn’t brake and crash into someone else? This is UNACCEPTABLE!!

So what do I do? Take it to the shop? I’ll have to wait several days to get my car back, providing I can even reproduce this problem to them, and pray they will know how to fix it. So I decided to take a shot at resolving it myself. What should you do when your electronics rebel? You guessed it. TURN IT OFF AND ON AGAIN. But I was driving 60 mph on the highway, people behind me wouldn’t like that so much :).

But first, what is the first step of fixing a problem? Reproduce it. Trying to put a destination in and driving around waiting for her (the GPS voice is female) to say something again is not a good way to recreate the bug :). So I dug in my GPS options and figured out that if I increased or decreased the navigation volume, she spoke again! It was supposed to be “Have a nice trip, drive carefully”, but instead it went “eh…trip, drive carefully” or “d.. carefully”. Well great, now I can quickly and consistently recreate the bug without driving aimless around like an idiot. First step, check!

Now it was time to try the number one fix for electronics. Off, on, off, on,…andddddd the problem was still there. Well, this was good and bad at the same time. Good because at least it was not random. Bad because now it wouldn’t magically fix itself. So now I think well, maybe if I changed to a different voice, like a man’s or a different language, maybe it would clear it up. Changed to a different female voice, still there. A man’s voice, still problematic. Changed to Italian instead of English, yep still dropping syllables. Ok that was worth a try…

Racking my brain to form a hypothesis, I thought this sounded like something was stuck in the sound buffer of the application. Maybe something was interfering with the sound coming out of the nav app. Logically, the next thing I checked was the audio app where you play music. Opening the interface, I saw it trying to play “0” songs with “0” names in folder “0/0”. Aw crap, yesterday I unplugged my thumb drive out of the USB slot after turning the car off because my wife needed it back. Ok guys, second rule of trying to fix a problem that comes out of nowhere: git blame! Cool, maybe my car was trying to play music from a drive that didn’t exist, that would definitely make things harder for my navigation to function correctly.

Knowing what went wrong, I changed the “source” of audio to radio, then turned the audio app off (without turning my car off) and on again. Voila, the thumb drive icon went dark (as it is not present). Ok now my car has registered that the device has been unplugged. Try GPS voice, yay, it’s gone, she speaks full English sentences again! For clarification, earlier I turned the car off and on, it automatically turned the audio app on again and got stuck at that invisible USB drive loop because the audio “source” wasn’t changed (sad trombone).

So there you have it, the steps off resolving an electronics problem are always consistent:
1. Reproduce it
2. Figure out what changed right before the problem surfaced
3. ???
4. Profit!

Posted in Meme, Programming | 1 Comment

A very koala post

Koala-Bear-Meme-2

Posted in Meme | Tagged | Leave a comment

How to initialize mail.dll exceptions

A colleague of mine wrote a good article about how frustrating it is to use a third-party library that you can’t easily setup unit tests. TL;DR – You can’t throw exceptions in your unit tests if the constructors are internal. Luckily I’ve found a way to accomplish that.

You see, mail.dll exceptions implement a protected constructor from the base Exception to be serializable. In this post I’ll show you how to initialize a mail.dll exception (or an exception that only has the serializable constructor)

[Serializable]
public class SmtpResponseException : ServerException
{
	protected SmtpResponseException(SerializationInfo info, StreamingContext context)
		: base(info, context)
	{
	}
}

You see, the base Exception class can initialize its subclass based on this protected constructor. If you take a look at what’s under the hood, it looks something like this:

protected Exception(SerializationInfo info, StreamingContext context)
{
  if (info == null)
    throw new ArgumentNullException("info");
  this._className = info.GetString("ClassName");
  this._message = info.GetString("Message");
  ...
}

So you would need to know exactly what dictionary key is used in order to work this constructor. Luckily, I’ve already done the heavy lifting so all you need to do is make a copy of the following class and voila!

/// <summary>
///    Nasty hacky class to create a new instance of SmtpResponseException.
/// </summary>
public class TestSmtpResponseException : SmtpResponseException
{
	protected TestSmtpResponseException(SerializationInfo info, StreamingContext context) : base(info, context) {}

	public static TestSmtpResponseException Create()
	{
		var info = new SerializationInfo(typeof (TestSmtpResponseException), new FormatterConverter());
		info.AddValue("ClassName", "foo");
		info.AddValue("Message", "bar");
		info.AddValue("InnerException", null);
		info.AddValue("HelpURL", null);
		info.AddValue("StackTraceString", null);
		info.AddValue("RemoteStackTraceString", null);
		info.AddValue("RemoteStackIndex", 0);
		info.AddValue("ExceptionMethod", null);
		info.AddValue("HResult", 1); // important, can't be 0
		info.AddValue("Source", null);
		return new TestSmtpResponseException(info, new StreamingContext(StreamingContextStates.Other)); // StreamingContextStates doesn't matter
	}
}

Now you can create an instance of the crazy i-wont-let-you-test-my-code mail.dll SmtpResponseException

var exception = TestSmtpResponseException.Create();

You can grab the full version of this code through my github

Happy unit testing!

Posted in Programming | Tagged , , | Leave a comment