{"action":"opened","issue":{"url":"https://api.github.com/repos/lxc/lxc/issues/723","labels_url":"https://api.github.com/repos/lxc/lxc/issues/723/labels{/name}","comments_url":"https://api.github.com/repos/lxc/lxc/issues/723/comments","events_url":"https://api.github.com/repos/lxc/lxc/issues/723/events","html_url":"https://github.com/lxc/lxc/issues/723","id":121848101,"number":723,"title":"Improve error handling","user":{"login":"brauner","id":7353573,"avatar_url":"https://avatars.githubusercontent.com/u/7353573?v=3","gravatar_id":"","url":"https://api.github.com/users/brauner","html_url":"https://github.com/brauner","followers_url":"https://api.github.com/users/brauner/followers","following_url":"https://api.github.com/users/brauner/following{/other_user}","gists_url":"https://api.github.com/users/brauner/gists{/gist_id}","starred_url":"https://api.github.com/users/brauner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brauner/subscriptions","organizations_url":"https://api.github.com/users/brauner/orgs","repos_url":"https://api.github.com/users/brauner/repos","events_url":"https://api.github.com/users/brauner/events{/privacy}","received_events_url":"https://api.github.com/users/brauner/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-12T10:43:58Z","updated_at":"2015-12-12T10:43:58Z","closed_at":null,"body":"Improve error handling in lxc\r\n\r\nAs we have discussed in a few mails error handling in lxc should be improved.\r\nHere are two different suggestions.\r\n\r\nWe should start by defining a set of reusable error codes which are modelled\r\nafter traditional C error codes. They should be put in a common header\r\n`lxc_error.h`. An example could be:\r\n\r\n        #define ELXCIDMAP 1 /* Indicates missing or invalid id mapping. /*\r\n\r\nAssociated with it we can have a really small set of error handling functions.\r\nSomething in the spirit of `strerror()` e.g. `lxc_strerror()` which turns the error\r\ncode into a human readable string that gives useful information about the error.\r\n\r\nThis should be the smallest common denominator for an error checking system. From\r\nthis point onward I see two possible ways to proceed.\r\n\r\n(1) Simple and fast error handling:\r\n\r\nWe keep an `error_num` variable in `struct lxc_container *current_config` which\r\ncontains the last error code which we can report back to the user.\r\n\r\n`error_num` will only be set by the api functions defined in lxccontainer.c.\r\n\r\n(2) Sophisticated error handling:\r\n\r\nThe more full-blown approach would probably be to define error codes per module.\r\nThat means we would have a simple `struct lxc_error` in `struct lxc_container\r\n*current_config` with a field for a module and an associated error code. A module\r\nhere would be e.g. bdev.h. `lxc_strerror()` would then take two arguments: module\r\nand error code and print an appropriate human readable string.\r\n\r\nIcing:\r\n\r\nWhen this is working we can discuss if we want to add a `struct lxc_list\r\n*error_list` that is a list of strings or error codes of all the things that went\r\nwrong. (In the spirit of what @hallyn suggested.)"}}