All Projects → mxcl → Legibleerror

mxcl / Legibleerror

Licence: unlicense
Beating `Error.localizedDescription` at its own game.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Legibleerror

Integrant
Micro-framework for data-driven architecture
Stars: ✭ 866 (+455.13%)
Mutual labels:  micro-framework
Jooby
The modular web framework for Java and Kotlin
Stars: ✭ 1,309 (+739.1%)
Mutual labels:  micro-framework
Flowbase
A Flow-based Programming inspired micro-framework / un-framework for Go (Golang)
Stars: ✭ 129 (-17.31%)
Mutual labels:  micro-framework
Nanohttp
A very micro HTTP framework.
Stars: ✭ 47 (-69.87%)
Mutual labels:  micro-framework
Unity Animator Helpers
A micro-framework for changing Unity 3D's Animator parameters with ScriptableObject(s). Designed to make going from custom scripts to Animator parameters easy. Works with 2D or 3D projects.
Stars: ✭ 89 (-42.95%)
Mutual labels:  micro-framework
Clask
Web micro-framework like flask in C++.
Stars: ✭ 110 (-29.49%)
Mutual labels:  micro-framework
Path.swift
Delightful, robust, cross-platform and chainable file-pathing functions.
Stars: ✭ 839 (+437.82%)
Mutual labels:  micro-framework
Micro Graphql
GraphQL Microservice
Stars: ✭ 145 (-7.05%)
Mutual labels:  micro-framework
Mini
Just an extremely simple naked PHP application, useful for small projects and quick prototypes. Some might call it a micro framework :)
Stars: ✭ 1,308 (+738.46%)
Mutual labels:  micro-framework
Meshki
Meshki: A Black-Colored, Responsive Boilerplate for UI Development
Stars: ✭ 129 (-17.31%)
Mutual labels:  micro-framework
Siler
⚡ Flat-files and plain-old PHP functions rockin'on as a set of general purpose high-level abstractions.
Stars: ✭ 1,056 (+576.92%)
Mutual labels:  micro-framework
Chubbyphp Framework
A based PSR-15 microframework that also sets maximum flexibility with minimum complexity and easy replaceability of the individual components, but also of the framework.
Stars: ✭ 69 (-55.77%)
Mutual labels:  micro-framework
Giraffe
Giraffe is an F# micro web framework for building rich web applications. It has been heavily inspired and is similar to Suave, but has been specifically designed with ASP.NET Core in mind and can be plugged into the ASP.NET Core pipeline via middleware. Giraffe applications are composed of so called HttpHandler functions which can be thought of a mixture of Suave's WebParts and ASP.NET Core's middleware.
Stars: ✭ 1,703 (+991.67%)
Mutual labels:  micro-framework
Picobox
Dependency injection framework designed with Python in mind.
Stars: ✭ 35 (-77.56%)
Mutual labels:  micro-framework
Tf
✔️ tf is a microframework for parameterized testing of functions and HTTP in Go.
Stars: ✭ 133 (-14.74%)
Mutual labels:  micro-framework
Mcp Panthor
A thin PHP microframework built on Slim and Symfony
Stars: ✭ 11 (-92.95%)
Mutual labels:  micro-framework
Cuba
Rum based microframework for web development.
Stars: ✭ 1,385 (+787.82%)
Mutual labels:  micro-framework
Azkarra Streams
🚀 Azkarra is a lightweight java framework to make it easy to develop, deploy and manage cloud-native streaming microservices based on Apache Kafka Streams.
Stars: ✭ 146 (-6.41%)
Mutual labels:  micro-framework
Slim
Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
Stars: ✭ 11,171 (+7060.9%)
Mutual labels:  micro-framework
Dom I18n
Provides a very basic HTML multilingual support using JavaScript
Stars: ✭ 125 (-19.87%)
Mutual labels:  micro-framework

LegibleError badge-platforms badge-languages badge-ci badge-codecov badge-version

LegibleError’s goal is to prevent you showing the user a string like this:

The operation couldn’t be completed. (ThirdPartyModule.(unknown context at 0xx10d6b4a44).SomeError error 0.)

That string is the default localizedDescription for a Swift Error. Instead use LegibleError and you’ll get something more like this:

The operation couldn’t be completed. (ThirdPartyModule.SomeError.networkFailure(http: 503))

Error.legibleLocalizedDescription

If you have an Error like this:

enum SystemError: Error {
    case databaseFailure(internalCode: Int)
}

let error = SystemError.databaseFailure
// ^^ obviously you’d get this from a callback or `catch` in the real-world

let alert = UIAlertController()
alert.message = error.localizedDescription
present(alert)

The alert will show:

The operation couldn’t be completed. (MyModule.(unknown context at 0xx10d6b4a44).SystemError error 0.)

But if we were to use .legibleLocalizedDescription:

import LegibleError

let alert = UIAlertController()
alert.message = error.legibleLocalizedDescription
present(alert)

The alert will show:

The operation couldn’t be completed. (SystemError.databaseFailure(internalCode: 34))

Still not great, but way more useful in a bug report.

If you want a great message, implement LocalizedError this will make both localizedDescription and legibleLocalizedDescription return the string you specify:

enum SystemError: LocalizedError {
    case databaseFailure
    
    var errorDescription: String? {
        switch self {
        case databaseFailure(let code):
            return "A serious database failure occurred. Contact support. (#\(code))"
        }
    }
}

The alert will show:

A serious database failure occurred. Contact support. (#34)


LegibleError exists because:

  1. You have no control over third parties and cannot force them to implement LocalizedError
  2. Some Errors in your codebase are very unlikely and thus “localizing” them is not a good maintenance burden.
  3. When logging errors you want the full information without any risk that the localized version has “fallen behind”, get the compiler to do the work, in such cases use legibleDescription (see the next section).

Loggable Error Descriptions

This:

let msg = "There was an error (\(error))"

Will give you this:

There was an error (databaseFailure)

Which loses the context of the enum’s type; use legibleDescription:

let msg = "There was an error! \(error.legibleDescription)"

There was an error (SystemError.databaseFailure(internalCode: 34))

legibleDescription is to description where legibleLocalizedDescription is to localizedDescription. legibleDescription is always appropriate for communicating to you, the developer, which error happened. Use it in logs and to supplement a good message for the user.

Way better descriptions on Linux

Linux is a little behind, usually you only get The operation could not be completed on Linux. We fully support Linux.

Supporting mxcl

Hi, I’m Max Howell and I have written a lot of open source software, and probably you already use some of it (Homebrew anyone?). I work full-time on open source and it’s hard; currently I earn less than minimum wage. Please help me continue my work, I appreciate it x

Other donation/tipping options

Installation

SwiftPM:

package.append(.package(url: "https://github.com/mxcl/LegibleError.git", from: "1.0.0"))

CocoaPods:

pod 'LegibleError', '~> 1.0'

Carthage:

Waiting on: @Carthage#1945.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].