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: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 theDispatcher 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
Error Classes
ErrorWithMetadata
Fromapp/src/lib/error-with-metadata.ts:23:
Usage Example
Retry Actions
TheretryAction metadata allows error handlers to offer retry functionality:
Git Error Context
ThegitContext provides additional details about Git operations:
Specialized Error Classes
CheckoutError
Fromapp/src/lib/error-with-metadata.ts:44:
DiscardChangesError
Fromapp/src/lib/error-with-metadata.ts:58:
CreateRepositoryError
Fromapp/src/lib/error-with-metadata.ts:70:
GitError
Wraps raw errors fromdugite (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
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)