{"id":21195549,"url":"https://github.com/slamko/ppx_catch","last_synced_at":"2025-06-29T13:33:08.247Z","repository":{"id":184066400,"uuid":"671196718","full_name":"slamko/ppx_catch","owner":"slamko","description":"Ocaml PPX for no-exception error handling  ","archived":false,"fork":false,"pushed_at":"2023-07-27T13:30:44.000Z","size":18324,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T21:41:43.760Z","etag":null,"topics":["error-handling","functional-programming","meta-programming","no-exception","ocaml","ppx","ppx-extension","ppx-rewriter","ppxlib"],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/slamko.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2023-07-26T19:04:10.000Z","updated_at":"2023-07-27T11:17:51.000Z","dependencies_parsed_at":"2025-03-14T21:41:22.417Z","dependency_job_id":"486f0373-8966-483c-8a1b-84d2ddb910f8","html_url":"https://github.com/slamko/ppx_catch","commit_stats":null,"previous_names":["slamko/ppx_catch"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/slamko/ppx_catch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slamko%2Fppx_catch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slamko%2Fppx_catch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slamko%2Fppx_catch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slamko%2Fppx_catch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slamko","download_url":"https://codeload.github.com/slamko/ppx_catch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slamko%2Fppx_catch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262600677,"owners_count":23335109,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","functional-programming","meta-programming","no-exception","ocaml","ppx","ppx-extension","ppx-rewriter","ppxlib"],"created_at":"2024-11-20T19:28:46.714Z","updated_at":"2025-06-29T13:33:08.234Z","avatar_url":"https://github.com/slamko.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"*** Simple PPX rewriter to catch exceptions and wrap the result into ('a, string) result\n**** Overview\n\nMay be useful to handle the case when the function inside List.map fails:\n#+begin_src ocaml\nlet%catch func lst =\n  List.map (fun x -\u003e\n    if x \u003e 0 then failwith \"Some problem\" else x + 1) lst \n#+end_src\n\nbecomes:\n#+begin_src ocaml\nlet%catch func lst =\n  try\n    Ok (List.map (fun x -\u003e\n      if x \u003e 0 then failwith \"Some problem\" else x + 1) lst)\n  with\n  | Failure err -\u003e Error (*[ \"func: \" + err ]*) (* error messages with tracing *)\n    (* and so on *) ...\n  | _ -\u003e Error \"func: Unknown error\" \n#+end_src\n\n\nExtension handles both top-level and \"embedded\" let bindings:\n#+begin_src ocaml\nlet foo =\n  let%catch wants_to_raise () = (* wrap some Stdlib function for example *)\n    (* some logic *)\n    failwith \"Stdlib exception\" (* call to Stdlib function that raises an exception *)\n  in\n\n  wants_to_raise () (* returns ('a, string) result *)\n#+end_src\n\nAlso works with \"function\" syntax:\n#+begin_src ocaml\nlet%catch wrap_function = function\n  | Some res -\u003e res\n  | None -\u003e failwith \"function syntax works too\"\n#+end_src\n\nIt basically wraps each case of the pattern matching.\n#+begin_src ocaml\nlet () =\n  match wrap_function None with\n  | Ok ok -\u003e Printf.printf \"Ok\\n\" ;\n  | Error err -\u003e Printf.printf \"%s\\n\" err ;\n  () \n\n#+end_src\nprints :\n#+begin_src sh\nwrap_function: function syntax works too\n#+end_src\n\n\n**** Quickstart\n\nTo instal this rewriter as opam package:\n#+begin_src sh\ngit clone https://github.com/slamko/ppx_catch.git \u0026\u0026\ncd ppx_catch \u0026\u0026\ndune build \u0026\u0026\nopam install .\n#+end_src\n\nNow to use it in your project add ppx_catch to library list\nand tell to use it as a preprocessor in your dune file:\n\n#+begin_src lisp\n(libraries\n            ppx_catch)\n(preprocess (pps ppx_catch))\n#+end_src\n\nFor a complete dune file example see test/dune\n\n**** LICENSE\nGPL-v3.0\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslamko%2Fppx_catch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslamko%2Fppx_catch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslamko%2Fppx_catch/lists"}