Skip to main content

Overview

GitHub Desktop distinguishes between two types of errors:
  • Exceptions: Unexpected, fatal problems requiring app restart
  • Errors: Expected runtime issues that can be handled gracefully
Both are represented by JavaScript’s Error class, but they’re conceptually different in how they’re handled.

Exceptions

Fatal Application Errors

An exception is an unexpected, fatal problem in the application itself that cannot be resolved at runtime. Examples:
  • undefined is not a function
  • Uncaught type errors
  • Null reference errors

Global Exception Handler

GitHub Desktop registers a global listener for uncaught exceptions:
When an exception occurs, the only option is to quit and relaunch the application.

Errors

Expected Runtime Errors

Errors are issues that can occur during normal application usage:
  • Network connectivity problems
  • Git repository in unexpected state
  • File system permission issues
  • API rate limiting

Error Flow Architecture

Error Dispatcher

Errors flow through the Dispatcher like most application events:

Error Handler Interface

Error handlers must have this signature:
1

Receive error and dispatcher

Handler gets the error object and dispatcher instance.
2

Inspect and handle

Check error type and handle if appropriate.
3

Return or swallow

Return the error (or a modified version) to pass along, or return null to stop propagation.

Registering Error Handlers

Handlers are invoked in reverse order (most recently registered first).

Error Classes

ErrorWithMetadata

From app/src/lib/error-with-metadata.ts:23:

Usage Example

Retry Actions

The retryAction metadata allows error handlers to offer retry functionality:
Error dialogs can present a “Retry” button that re-executes the failed action.

Git Error Context

The gitContext provides additional details about Git operations:
This helps error handlers provide specific guidance on recovery.

Specialized Error Classes

CheckoutError

From app/src/lib/error-with-metadata.ts:44:
Usage:

DiscardChangesError

From app/src/lib/error-with-metadata.ts:58:

CreateRepositoryError

From app/src/lib/error-with-metadata.ts:70:

GitError

Wraps raw errors from dugite (the Git wrapper) with additional Git-specific information:

Error Handler Examples

Repository-Specific Handler

Network Error Handler

Git Conflict Handler

Best Practices

Creating Errors

1

Use specific error classes

Use CheckoutError, DiscardChangesError, etc. when appropriate.
2

Include metadata

Add repository, retry action, and git context information.
3

Preserve original error

Wrap rather than replace the original error.

Error Messages

Make error messages user-friendly and actionable. Avoid technical jargon.

Error Handlers

Debugging Errors

Logging

Error Tracking

Errors reported to error tracking service include:
  • Error message and stack trace
  • Application version and platform
  • User actions leading to error
  • Repository state (sanitized)

Testing Error Paths