Advertisements

Blog: Creative fix to a silent fail in Shortcuts

As part of MDM Deals 2.1, the MDM Deals blog is a place not just for announcements about the site, but also for some “behind the scenes” of how those updates are made. If you love technology, you’ll be interested in the tricks I use to make all this work.

Today I’m excited to announce two bug fixes. First is a major error you’ve probably noticed where a app on sale is published without its name, logo, or App Store link. Oops. Second is a tiny one, removing the extra space that sometimes appeared before a semi-colon.  Those are fixed now! If all you care about is the update, read no further! If you care how I fixed it–read on.

Error 1: Posts without names, logos, prices, or links

The first error was that posts would go live without an app name, app icon, price, or link to the app in the App Store. It looked like this:

linkless-post

Pretty awful. And not just ugly–it defeated the entire point of the site because you couldn’t get to the deal. If I noticed the mistake, I would manually repost the item and then redirect the bad post to the new post, but I didn’t always noticed, it was tedious manual work, and the mistake had already automatically propagated all over the internet.

First I had to figure out the problem–diving into my AppDeal Shortcuts shortcut, I found the error. Normally, I type the name of an app into my shortcut and use the “Find app in App Store” action to return a list of results; I then choose and app and the shortcut auto-generates the name, image, price, and link. But if the “Find app in App Store” fails to find a match in the App Store, it doesn’t give me an alert–it just continues to generate a name, image, price, and link–all blank because it had no point of reference. The result was a blank post.

Now, if I was really good, I could have mentally remembered that the “Find app” action fails silently–if I saw no list of results, it meant it hadn’t found an app. But I never noticed a silent fail and was constantly fixing things after the fact. No, I needed an automated preventive measure so I didn’t propagate an error 15 different places on the internet. I had to create an error message if the “Find app” action didn’t return any results.

My idea was that I could tell Shortcuts to see if the app name, price, or link were blank variables. If so, then the “find app” action hadn’t found an app and had failed silently; if not, and those contained content, then the “find app” action had, indeed, found an app. I first tried to  run an “if” condition on the app name to see if it “matched” nothing–but this simply didn’t work. An if condition can match content, but it can’t match nothing. So then I figured I’d search “contains” a character, but that is problematic because the “if” condition doesn’t search a regular expression (regex). I could create nested if conditionals, each one searching for a vowel or number but that would be ridiculously long and complex.

The answer was regex, so I ran a “match text” action on the name variable, searching for any alphanumeric character. Perfect: if the name variable had content, it matched; if it didn’t have content, it didn’t match. But now I needed to turn the regex result into an if conditional to give me an error if there was no match.

The way to do that wasn’t intuitive, but it worked: count the items in the regex match and, if the count was 1 or more, it meant the regex had matched content. If the count was less than 1, then the regex hadn’t matched any content and the “find app” action had failed silently. It was then as simple as creating an alert when the if conditions were met!

Update: With the help of the internet (shout out to u/Chaupin), I now realize there’s no need to run regex first. Instead, if you just run “count” on the name variable, it returns the same result of “1” if it contains something and “0” if it’s empty. That eliminates an action step and is a cleaner solution!

Here’s the final (updated) result:

silent-fail-2

Here are the steps the Shortcut goes through:

  1. Gets the name of the app chosen from the App Store. This will be empty if “Find app” had failed, but it will contain content if it worked.
  2. Saves that result as a variable.
  3. Runs a regular expression (regex) on that variable, searching for any alphanumeric character.
  4. Counts the number of items matched by that regex in that variable. If the variable holds content, it will count it. If there isn’t content in the variable, then there will be no items to count.
  5. The if-statement gives me a cheeky alert if the count is less than 1, meaning that the regex matched nothing and thus the variable is empty. I then have it automatically exit the shortcut so I can’t mess it up. If there is more than 1 item to count, the if-condition does nothing and continues on like normal.

There you have it! An automated way to make sure a silent fail in Shortcuts doesn’t result in a pointless and ugly post. You can download this section of the Shortcut here.

Error 2: an extra space before a semi-colon

So this is admirably not nearly as big a deal as the first error, but it’s one that bugged me. I would sometimes leave an extra space after I described an app; when Shortcuts auto-added ratings, it would also add a semi-colon after that space. It looked like this:

image.png

I’m not sure anyone else noticed that, but I want MDM Deals to be a delightful experience and things like that bug me. Apple fans love great design and attention to detail, after all.

Now, again, I could have tried to just remember NOT to insert an extra space after typing my description. But why force my brain to remember to do something like that when I can automate it for guaranteed accuracy?

It wasn’t a hard fix. All I needed was a snippet of regex to replace any space that appears at the end of a line–\s$–and voila, problem solved.

remove-end-space-regex

Last thoughts on automation

This is what I love about Shortcuts and the automation it enables. I’m not a developer, I can’t write a script, and I can only barely hack my way around regex, but that doesn’t matter. Shortcuts democratized automation enables me not only to post deals to 15 different places on the internet, but it also enables me to prevent or fix user errors automatically.

I now don’t have to worry now about mistyping an app name or inserting extra spaces. A tiny bit of automation not only guarantees better quality posts for MDM Deals but also takes away yet one more thing I have to think about 8-10 times a day when I post deals. Faster posts, better deals, and less mental effort? I’ll take that any day.

@MarkDMill

I run MDM Deals, a site where I help you discover great deals on fantastic apps & movies. Every day, hundreds of apps and movies go on sale but most are junk; I curate and publish just the best deals on just the best items. See all today’s deals and the 15 places you can follow deals across the internet!

Advertisements

Comments are closed.

Up ↑

%d bloggers like this: