{"id":18098609,"url":"https://github.com/makiftutuncu/errors","last_synced_at":"2026-03-06T08:34:13.668Z","repository":{"id":57721410,"uuid":"50101565","full_name":"makiftutuncu/Errors","owner":"makiftutuncu","description":"An easy-to-use library written in Scala for providing immutable, lightweight, extensible way to represent errors in your project","archived":false,"fork":false,"pushed_at":"2023-12-15T14:48:03.000Z","size":1078,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-14T17:26:19.707Z","etag":null,"topics":["error-handling","errors","library","scala"],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/makiftutuncu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-21T10:56:53.000Z","updated_at":"2019-07-13T19:36:16.000Z","dependencies_parsed_at":"2023-12-15T15:55:34.957Z","dependency_job_id":null,"html_url":"https://github.com/makiftutuncu/Errors","commit_stats":null,"previous_names":["mehmetakiftutuncu/errors"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/makiftutuncu/Errors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makiftutuncu%2FErrors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makiftutuncu%2FErrors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makiftutuncu%2FErrors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makiftutuncu%2FErrors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/makiftutuncu","download_url":"https://codeload.github.com/makiftutuncu/Errors/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makiftutuncu%2FErrors/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30167963,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T07:56:45.623Z","status":"ssl_error","status_checked_at":"2026-03-06T07:55:55.621Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["error-handling","errors","library","scala"],"created_at":"2024-10-31T20:12:11.311Z","updated_at":"2026-03-06T08:34:13.640Z","avatar_url":"https://github.com/makiftutuncu.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"Errors [![Build Status](https://travis-ci.org/mehmetakiftutuncu/Errors.svg?branch=master)](https://travis-ci.org/mehmetakiftutuncu/Errors)\n======\n\nErrors is an easy-to-use library written in Scala for providing immutable, lightweight, extensible way to represent errors in your project.\n\nHow to Include in Your Project\n--------------\nAdd following to your ```build.sbt``` if you are using **SBT**\n```sbt\nlibraryDependencies += \"com.github.mehmetakiftutuncu\" %% \"errors\" % \"1.2\"\n```\n\nOr add following to your ```pom.xml``` if you are using **Maven** (use **errors_2.11** for **Scala 2.11**)\n```xml\n\u003cdependency\u003e\n\t\u003cgroupId\u003ecom.github.mehmetakiftutuncu\u003c/groupId\u003e\n\t\u003cartifactId\u003eerrors_2.12\u003c/artifactId\u003e\n\t\u003cversion\u003e1.2\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nOr add following to your ```build.gradle``` if you are using **Gradle** (use **errors_2.11** for **Scala 2.11**)\n```gradle\ncompile 'com.github.mehmetakiftutuncu:errors_2.12:1.2'\n```\n\nExamples\n--------------\nSince Errors is immutable, any kind of update operation (i.e. any method returning [```Errors```](src/main/scala/com/github/mehmetakiftutuncu/errors/Errors.scala) or any error extending [```ErrorBase```](src/main/scala/com/github/mehmetakiftutuncu/errors/base/ErrorBase.scala)) return a new copy with new data.\n\n### Creating an Errors Instance\nYou can easily create both empty and non-empty [```Errors```](src/main/scala/com/github/mehmetakiftutuncu/errors/Errors.scala) instances. Just use ```empty``` or ```apply``` methods.\n\n**Example**\n```scala\n// Empty errors\nval errors1 = Errors.empty\nval errors2 = Errors()\n\n// Non-empty errors already containing given errors\nval errors3 = Errors(CommonError.timeout, SimpleError.authorization)\n```\n\n****\n\n### Creating Error Objects\nYou can create error objects to add to or remove from or even perform checks on an ```Errors``` instance. There are 2 types of errors already defined; [```CommonError```](src/main/scala/com/github/mehmetakiftutuncu/errors/CommonError.scala) and [```SimpleError```](src/main/scala/com/github/mehmetakiftutuncu/errors/SimpleError.scala). However, you can use any type of errors as long as they extend from [```ErrorBase```](src/main/scala/com/github/mehmetakiftutuncu/errors/base/ErrorBase.scala).\n\n**Example**\n```scala\n// You can provide all info.\nval error1 = CommonError(name = \"invalidData\", reason = \"Value must be a positive integer.\", data = \"-5\")\n\n// You can provide some info and update reason and data of a CommonError later.\nval error2 = CommonError(\"timeout\").reason(\"Network might be down.\").data(\"30 seconds\")\n\n// There are even some predefined helper methods to give you appropriate instances easily. \nval error3 = CommonError.authorization.reason(\"Username or password is invalid!\")\n\n// Literally \"simple\", just an error name\nval error4 = SimpleError(\"database\")\nval error5 = SimpleError.timeout\n```\n\n****\n\n### Adding Errors\nYou can add a single error, multiple errors or the errors in an existing ```Errors``` instance to an ```Errors``` instance.\n\n**Example**\n```scala\nval errors1 = Errors.empty\nval errors2 = Errors(SimpleError.authorization)\n\nval errors3 = errors1 + CommonError.timeout\n\nval errors4 = errors1.addAll(CommonError.timeout, SimpleError.authorization)\n\nval errors5 = errors3 ++ Errors(SimpleError.authorization)\n```\n\n****\n\n### Removing Errors\nYou can remove a single error, multiple errors or the errors in an existing ```Errors``` instance from an ```Errors``` instance.\n\n**Example**\n```scala\nval errors1 = Errors(CommonError.timeout, SimpleError.authorization)\n\nval errors2 = errors1 - CommonError.timeout\n\n// Database error will be ignored here since it does not exist in errors1 anyway.\nval errors3 = errors1.removeAll(SimpleError.authorization, CommonError.database)\n\nval errors4 = errors1 -- Errors(SimpleError.authorization)\n```\n\n****\n\n### Checking Errors Instance for Errors\nYou can perform several checks on an ```Errors``` instance.\n\n**Example**\n```scala\nval errors1 = Errors(CommonError.timeout, SimpleError.authorization)\nval errors2 = Errors.empty\n\nerrors1.isEmpty // false\nerrors2.isEmpty // true\n\nerrors1.nonEmpty // true\nerrors2.nonEmpty // false\n\nerrors1.hasErrors // true\nerrors2.hasErrors // false\n\nerrors1.size // 2\nerrors2.size // 0\n\nerrors1.numberOfErrors // 2\nerrors2.numberOfErrors // 0\n\nerrors1.contains(CommonError.timeout)  // true\nerrors1.contains(CommonError.database) // false\nerrors2.contains(CommonError.timeout)  // false\n\n// true\nerrors1.exists {\n  case CommonError(name, _, _) if name == \"timeout\" =\u003e true\n  case _ =\u003e false\n}\n```\n\n****\n\n### Using Maybe\nThere is a type alias for ```Either[Errors, V]``` defined as [```Maybe```](src/main/scala/com/github/mehmetakiftutuncu/errors/package.scala). It can be useful for error handling while accessing a value.  \n\n**Example**\n```scala\n// Method will either return some Errors or an Int\ndef divide(n1: Int, n2: Int): Maybe[Int] = {\n  if (n2 == 0) {\n    // Create maybe with Errors\n    Maybe(Errors(CommonError.invalidData.reason(\"Cannot divide by 0!\")))\n  } else {\n    // Create Maybe with a value\n    Maybe(n1 / n2)\n  }\n}\n\nval result1: Maybe[Int] = divide(3, 0)\nval result2: Maybe[Int] = divide(4, 2)\n\nresult1.maybeErrors // Returns Some(Errors(CommonError.invalidData.reason(\"Cannot divide by 0!\")))\nresult2.maybeErrors // Returns None\n\nresult1.maybeValue // Returns None\nresult2.maybeValue // Returns Some(2)\n\nresult1.hasErrors // Returns true\nresult2.hasErrors // Returns false\n\nresult1.hasValue // Returns false\nresult2.hasValue // Returns true\n\n// Methods below throw exceptions unless their criteria are met. So, use them with caution!\n\nresult1.errors // Returns Errors(CommonError.invalidData.reason(\"Cannot divide by 0!\"))\nresult2.errors // Throws HasNoErrorsException!\n\nresult1.value // Throws HasNoValueException!\nresult2.value // Returns 2\n```\n\n****\n\n### Representing Errors\nAs default implementation, ```Errors``` will use [```JsonStringErrorRepresenter```](src/main/scala/com/github/mehmetakiftutuncu/errors/representation/JsonStringErrorRepresenter.scala) and give a Json formatted string representation of all errors as an array. You may also provide your own error representer extending [```ErrorRepresenter```](src/main/scala/com/github/mehmetakiftutuncu/errors/representation/ErrorRepresenter.scala) so you can represent your errors in any way you want.\n\n**Example**\n```scala\nval error1 = CommonError(name = \"foo\")\nval error2 = CommonError(name = \"foo\", reason = \"bar\")\nval error3 = CommonError(name = \"foo\", data = \"bar\")\nval error4 = CommonError(name = \"foo\", reason = \"bar\", data = \"baz\")\nval error5 = SimpleError(name = \"goo\")\nval errors = Errors(error1, error2, error3, error4, error5)\n\n// Output will be\n// [{\"name\":\"foo\"},{\"name\":\"foo\",\"reason\":\"bar\"},{\"name\":\"foo\",\"data\":\"bar\"},{\"name\":\"foo\",\"reason\":\"bar\",\"data\":\"baz\"},{\"name\":\"goo\"}]\nerrors.represent(includeWhen = false)\nerrors.toString\n\n// Output will be\n// [{\"name\":\"foo\",\"when\":1454271634493},{\"name\":\"foo\",\"reason\":\"bar\",\"when\":1454271634557},{\"name\":\"foo\",\"data\":\"bar\",\"when\":1454271634621},{\"name\":\"foo\",\"reason\":\"bar\",\"data\":\"baz\",\"when\":1454271634680},{\"name\":\"goo\",\"when\":1454271634737}]\nerrors.represent(includeWhen = true)\n\n// Custom error representer giving true unless Errors is empty, for demonstration purposes\nval customBooleanRepresenter = new ErrorRepresenter[Boolean] {\n  override def represent(error: ErrorBase, includeWhen: Boolean): Boolean = true\n  override def represent(errors: List[ErrorBase], includeWhen: Boolean): Boolean = if (errors.isEmpty) false else true\n  override def asString(representation: Boolean): String = representation.toString\n}\n\nErrors.empty.represent(customBooleanRepresenter, includeWhen = false) // Returns false\nerrors.represent(customBooleanRepresenter, includeWhen = true)        // Returns true\n```\n\nYou can see a real error representer example in [```JsonErrorRepresenter```](samples/PlayFrameworkExample/app/controllers/JsonErrorRepresenter.scala).\n\nContributing\n--------------\nI'd appreciate if you comment, file an issue, send pull requests. Please feel free to and do contribute.\n\n### Contributors\n\n* [**@forthy**](https://github.com/forthy) - Cross compilation for Scala 2.11 and 2.12\n\nLicense\n--------------\nThe MIT License (MIT), Copyright (c) 2016 Mehmet Akif Tütüncü\n\nSee [**LICENSE.md**](LICENSE.md) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakiftutuncu%2Ferrors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmakiftutuncu%2Ferrors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakiftutuncu%2Ferrors/lists"}