{"id":20564501,"url":"https://github.com/tarantool/errors","last_synced_at":"2025-04-14T15:11:33.909Z","repository":{"id":33910286,"uuid":"98996355","full_name":"tarantool/errors","owner":"tarantool","description":"Error objects with stack trace support","archived":false,"fork":false,"pushed_at":"2023-03-21T12:15:40.000Z","size":70,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-28T04:05:14.228Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","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/tarantool.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-01T11:59:38.000Z","updated_at":"2022-10-27T12:35:58.000Z","dependencies_parsed_at":"2023-01-15T03:18:01.714Z","dependency_job_id":null,"html_url":"https://github.com/tarantool/errors","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Ferrors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Ferrors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Ferrors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Ferrors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tarantool","download_url":"https://codeload.github.com/tarantool/errors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248904640,"owners_count":21180835,"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":[],"created_at":"2024-11-16T04:27:19.584Z","updated_at":"2025-04-14T15:11:33.876Z","avatar_url":"https://github.com/tarantool.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Convenient error handling in tarantool\n\nBecause Lua code deserves better error handling. This module helps you\nunderstand what code path lead to creation of a particular exception\nobject.\n\n## Example\n\n```lua\nerrors = require('errors')\n\nDoSomethingError = errors.new_class(\"DoSomethingError\")\n\nfunction do_something()\n    local failure_condition = true\n    local result = \"bar\"\n\n    if failure_condition then\n        return nil, DoSomethingError:new(\"failure_condition is true\")\n    end\n\n    return result\nend\n\nres, err = do_something()\n\nif err ~= nil then\n    print(err)\nend\n```\n\nThis code will print:\n\n```console\nDoSomethingError: failure_condition is true\nstack traceback:\n    test.lua:10: in function 'do_something'\n    test.lua:16: in main chunk\n```\n\nSee that you have an exception type, message and traceback recorded\ninside the exception object. It can be converted to string using the\n`tostring()` function.\n\n## Uniform error handling\n\nThe module praises uniform error handling and provides `pcall` API,\nwhich unifies return values:\n\n```console\n\u003e print( DoSomethingError:pcall(do_something) )\nnil     DoSomethingError: failure_condition is true\nstack traceback:\n    test.lua:10: in function 'do_something'\n    test.lua:16: in main chunk\n\n\u003e print( DoSomethingError:pcall(error, 'some functions still raise') )\nnil     DoSomethingError: some functions still raise\nstack traceback:\n        [C]: in function 'xpcall'\n        /opt/errors/errors.lua:139: in function 'pcall'\n        [string \"return print( DoSomethingEr\"]:1: in main chunk\n```\n\nIn both cases `pcall` returns the same pattern `nil, err`.\n\nIf there were no error raised, `pcall` doesn't modify any return values:\n\n```console\n\u003e print( DoSomethingError:pcall(function() return nil, \"foo\", \"bar\" end) )\nnil     foo     bar\n```\n\n## Uniform API for net.box stuff\n\nIt may be tricky to debug errors, when they arise on a remote host:\n`net.box` throws an exception and doesn't keep stack trace from the remote.\n\nTo simplify debugging in this case use `return nil, err` pattern with\nconjunction of `errors.netbox_eval` or `netbox_call`. It'll collect\nstacktrace from both local and remote hosts and restore metatables\n(which can't be transfed over network).\n\n```console\n\u003e conn = require('net.box').connect('localhost:3301')\n\u003e print( errors.netbox_eval(conn, 'return nil, DoSomethingError:new(\"oops\")') )\nnil     DoSomethingError: oops\nstack traceback:\n        eval:1: in main chunk\nduring net.box eval on localhost:3301\nstack traceback:\n        [string \"return print( errors.netbox_eval(\"]:1: in main chunk\n        [C]: in function 'pcall'\n```\n\n## Naming conventions\n\n* Error class should be named in `CamelCase`.\n* Error class should end with suffix `Error`.\n* See examples: `ReadFileError`, `DecodeYamlError`, `CheckSchemaError`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarantool%2Ferrors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftarantool%2Ferrors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarantool%2Ferrors/lists"}