Tip 49 – How to find your Data Service bug

I’ve been playing around with creating a custom Astoria Data Service Provider, aka DSP, for a while now.

So far I’d managed to get my metadata all setup, so browsing to $metadata works great. I’d got a few simple queries work.

Basically everything was going fine.

At least until I tried this URL:

Bug

I wasn’t sure what was going on exactly, and I couldn’t get any help from Fiddler, because it was having problems with the built-in VS web server.

And because my DSP was by design loosely typed, if I needed to spot the difference between this (bad):

BuggyCode

And this (good):

GoodCode

Can you see the problem?

If you can good on ya, you’ve got sharper eyes than me…

Turns out that you don’t need sharp eyes, you just need to know about HandleException on DataService<> which you can override something like this:

image

Once I did this it was easy to spot that one of my dictionaries had an entry keyed on ID rather than Id.

After making the fix my query worked just great:

Working

Knowing about HandleException is absolutely vital when developing an DSP, but it is more generally useful too, for things like auditing, error logging, you name it.

Oh and did you notice that my DSP exposes data from a list of dictionaries?

That is a story for another day ;)