Skip to main content
coreydaley.dev

Crash reporting with no network: .ips files, a scrubber, and mailto:

Purrchiver doesn’t talk to a server, and I didn’t want a crash SDK in it. But when it crashes, I want to know where. The usual answer, a framework like Sentry or Crashlytics, means an SDK uploading data in the background, which is exactly what I’d promised not to ship. So the crash reporter uses what macOS already writes, removes anything that identifies you, and gives you an email you can read, edit, and choose to send.

Off by default, one prompt at most

The prompt is opt-in. It’s off unless you turn on Settings → General → Error reporting (the welcome tour offers the same switch). With it on, Purrchiver checks for a new crash once at launch, and shows at most one sheet: the most recent crash it hasn’t already offered. The sheet shows the exact text that would go out. Send via Mail opens your mail client with that text in a new message, and nothing has gone anywhere yet. Copy to Clipboard is there for webmail. You can also dismiss it, or stop it asking about that crash.

Reading macOS’s own crash files

When an app crashes, macOS writes an .ips file to ~/Library/Logs/DiagnosticReports/, named after the process: Purrchiver-<date>-<time>.ips. An .ips file is two JSON documents. The first line is a small header with the bundle ID, app name, and timestamp. The rest is the report: the exception, every thread, and the list of loaded images.

The reporter keeps files whose names start with the process name and end in .ips, newest first, and skips anything older than the last crash it offered. It then requires the header’s bundleID to match exactly before it parses the rest. From the body it keeps very little:

  • the exception type, signal, and subtype
  • the top eight frames of the thread that crashed, each as image name, symbol, and offset

The full .ips file never leaves the Mac. Only that summary does.

Update, October 23: The App Store build is stripped, so the app’s own frames often have no symbol to show. In 1.1 each frame also keeps its offset into its image, and the summary adds the image’s build UUID, its architecture and the app version, which is what atos needs to turn a stripped frame back into a function name.

The sandbox question. In the App Sandbox, FileManager.default.homeDirectoryForCurrentUser is the app’s container, not your real home folder. The reporter is designed around the sandbox letting an app read its own crash reports at that path. That’s what its design depends on, and I haven’t found Apple documentation for it. If it doesn’t hold, the scan finds nothing and the reporter quietly does nothing. No error, no prompt.

The scrubber is the part that matters

The email is the only way crash data leaves the Mac, so the scrubber is what makes the opt-in safe to offer. Every field passes through it before you see it, in this order:

  1. Your home path becomes /Users/<redacted>.
  2. Any /<username>/ path component, which also catches per-user temp folders, becomes /<redacted>/.
  3. Your username as a standalone word becomes <redacted>.
  4. Any /Users/<name> at all, not just yours, is redacted. A frame’s image path can include a different account’s home.
  5. /Volumes/… is redacted to the end of the line, because external drive names identify people (“Corey’s SSD”).
  6. Mobile Documents/… (iCloud Drive) is redacted to the end of the line.

Steps 5 and 6 go to the end of the line because volume names and iCloud paths often contain spaces, and in a stack trace those paths come last on the line. Stopping at the first space would leave half a folder name behind.

Step 3 took two rounds. A plain find-and-replace on a short username wrecks the report: a user named tom turns customRange into cus<redacted>Range. The first version avoided that with a minimum length, replacing only longer usernames. On June 7 the minimum dropped to three characters, and on June 18 it went entirely. A word-boundary regex already prevents the false matches, and macOS allows one- and two-character short usernames, which the minimum had been leaking:

let pattern = "\\b" + NSRegularExpression.escapedPattern(for: username) + "\\b"
let regex = try NSRegularExpression(pattern: pattern)
text = regex.stringByReplacingMatches(in: text,
                                      range: NSRange(text.startIndex..., in: text),
                                      withTemplate: "<redacted>")

\b needs a change between a word character and a non-word character, so tom inside customRange doesn’t match, and user=tom does. The scrubber is a pure function, idempotent, and tested on its own: fourteen tests, including a two-character username, a volume name with spaces, and an iCloud path. The diagnostic-log export in Settings → Advanced runs its text through the same function.

Building the mailto: URL

mailto: looks trivial and has two traps.

Encoding. .urlQueryAllowed lets & and + through unescaped. In a mailto: query, & starts a new field and + can be read as a space, so a stack frame with & in it would end the body early. Remove them from the allowed set:

let allowed = CharacterSet.urlQueryAllowed.subtracting(CharacterSet(charactersIn: "&+"))
let body = text.addingPercentEncoding(withAllowedCharacters: allowed) ?? ""
let url = URL(string: "mailto:\(address)?subject=\(subject)&body=\(body)")

Length. Mail clients can truncate a long mailto: URL without telling you where. So the body is capped at about 60,000 bytes before encoding, cut back to the last full line, and given a footer that says how much was left out. A crash summary is far smaller than that. The cap matters more for the log export, which uses the same builder.

Update, October 23: That cap was measured wrong. It was checked against the raw UTF-8 length when the limit applies to the percent-encoded body, and the cut could land in the middle of a multi-byte character and crash the app. In 1.1 the body is trimmed by its encoded length, between whole characters. I wrote up both that and a crash-grouping bug in Two bugs in my crash reporter.

What to take away

  • macOS already writes good crash reports. For an app that can’t phone home, reading .ips files is enough to find most bugs.
  • Send a summary, not the whole file. Exception plus top frames is usually enough, and it’s a lot less to scrub.
  • Scrub with word boundaries, not length limits, and redact paths with spaces to the end of the line.
  • Escape & and + yourself in mailto: bodies, and cap the length.
  • Show the user exactly what they’re sending, and keep the whole thing opt-in.

Related posts