{"id":23902863,"url":"https://github.com/mtumilowicz/java11-error-messages-using-enum","last_synced_at":"2026-07-13T01:31:58.800Z","repository":{"id":110876872,"uuid":"166861299","full_name":"mtumilowicz/java11-error-messages-using-enum","owner":"mtumilowicz","description":"Simple implementation of handling error messages using enum.","archived":false,"fork":false,"pushed_at":"2019-01-25T20:48:58.000Z","size":68,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-25T20:17:53.434Z","etag":null,"topics":["error-handling","error-messages"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mtumilowicz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2019-01-21T18:32:57.000Z","updated_at":"2019-01-25T20:48:59.000Z","dependencies_parsed_at":"2023-03-13T13:47:38.156Z","dependency_job_id":null,"html_url":"https://github.com/mtumilowicz/java11-error-messages-using-enum","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mtumilowicz/java11-error-messages-using-enum","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava11-error-messages-using-enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava11-error-messages-using-enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava11-error-messages-using-enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava11-error-messages-using-enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtumilowicz","download_url":"https://codeload.github.com/mtumilowicz/java11-error-messages-using-enum/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava11-error-messages-using-enum/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35407393,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-12T02:00:06.386Z","response_time":87,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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","error-messages"],"created_at":"2025-01-04T22:50:55.678Z","updated_at":"2026-07-13T01:31:58.794Z","avatar_url":"https://github.com/mtumilowicz.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/mtumilowicz/java11-error-messages-using-enum.svg?branch=master)](https://travis-ci.com/mtumilowicz/java11-error-messages-using-enum)\n\n# java11-error-messages-using-enum\nSimple implementation of handling error messages using enum.\n\n# preface\nCreating enum with error messages is very handy practice\nwhen you try to write your code without exceptions (by \nusing `Either` for example). For `Either` basics you should refer\nmy other github repo: https://github.com/mtumilowicz/java11-vavr-either\n\n# project description\n* Suppose we have `Sender` class:\n    ```\n    public class Sender {\n        public Either\u003cString, Send\u003e send(Order order) {\n            if (!order.isComplete()) {\n                return Either.left(OrderErrorMessages.INCOMPLETE.message);\n            }\n            \n            return Either.right(new Send(order));\n        }\n    }\n    ```\n    * when the order is complete - sends it\n    * when the order is incomplete - message\n\n* We could model it in two different ways:\n    1. by throwing exception\n    1. by returning `Either`\n    \n    In each case error messages stored in enum is a good approach\n    but when it comes to `Either` - it is very natural.\n    \n* error messages\n    ```\n    public enum OrderErrorMessages {\n        INCOMPLETE(\"Order should be completed before sending it.\");\n        public final String message;\n    \n        OrderErrorMessages(String message) {\n            this.message = message;\n        }\n    }\n    ```\n\n* `Order` and `Send` are as simple as they can be:\n    ```\n    @Value\n    class Send {\n        Order order;\n    }\n    \n    @Value\n    @AllArgsConstructor(access = AccessLevel.PRIVATE)\n    class Order {\n        boolean complete;\n        \n        static Order incomplete() {\n            return new Order(false);\n        }\n        \n        static Order complete() {\n            return new Order(true);\n        }\n    }\n    ```\n**Shown approach with error messages encapsulated in enum\n    are much more cleaner than putting them in properties files\n    or literal strings.**\n# tests\n```\ndef \"test send complete order\"() {\n    given:\n    def sender = new Sender()\n    def order = Order.complete()\n\n    when:\n    def send = sender.send(order)\n\n    then:\n    send.isRight()\n    send.get().order == order\n}\n\ndef \"test send incomplete order\"() {\n    given:\n    def sender = new Sender()\n    def order = Order.incomplete()\n\n    when:\n    def send = sender.send(order)\n\n    then:\n    send.isLeft()\n    send.getLeft() == \"Order should be completed before sending it.\"\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtumilowicz%2Fjava11-error-messages-using-enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtumilowicz%2Fjava11-error-messages-using-enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtumilowicz%2Fjava11-error-messages-using-enum/lists"}