{"action":"closed","issue":{"url":"https://api.github.com/repos/facebook/componentkit/issues/585","repository_url":"https://api.github.com/repos/facebook/componentkit","labels_url":"https://api.github.com/repos/facebook/componentkit/issues/585/labels{/name}","comments_url":"https://api.github.com/repos/facebook/componentkit/issues/585/comments","events_url":"https://api.github.com/repos/facebook/componentkit/issues/585/events","html_url":"https://github.com/facebook/componentkit/issues/585","id":164030627,"number":585,"title":"Question - Best practice for error handling","user":{"login":"avnerbarr","id":2404795,"avatar_url":"https://avatars.githubusercontent.com/u/2404795?v=3","gravatar_id":"","url":"https://api.github.com/users/avnerbarr","html_url":"https://github.com/avnerbarr","followers_url":"https://api.github.com/users/avnerbarr/followers","following_url":"https://api.github.com/users/avnerbarr/following{/other_user}","gists_url":"https://api.github.com/users/avnerbarr/gists{/gist_id}","starred_url":"https://api.github.com/users/avnerbarr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avnerbarr/subscriptions","organizations_url":"https://api.github.com/users/avnerbarr/orgs","repos_url":"https://api.github.com/users/avnerbarr/repos","events_url":"https://api.github.com/users/avnerbarr/events{/privacy}","received_events_url":"https://api.github.com/users/avnerbarr/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/facebook/componentkit/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-07-06T09:05:02Z","updated_at":"2016-08-17T19:25:28Z","closed_at":"2016-08-17T19:25:28Z","body":"Since the component's root is updated through a class method and asynchronously in some cases, I am curious about the best way to handle errors while building a component hierarchy.\r\n\r\nI came across a situation where the error only appears when returning the root component (one of the components can \"throw\" an error derived from an illegal model).\r\n\r\nFor instance in the case below:\r\n```\r\n// view controller\r\n- (void)viewDidLoad {\r\n...\r\n_ckView = [[CKComponentHostingView alloc] initWithComponentProvider:[self class]\r\n                                                      sizeRangeProvider:_sizeRangeProvider];\r\n...\r\n[_ckView updateModel:viewModel mode:CKUpdateModeSynchronous]; \r\n}\r\n\r\n// the callback:\r\n#pragma mark - CKComponentProvider\r\n\r\n+ (CKComponent *)componentForModel:(Model *)model context:(ComponentContext *)context {\r\n.... // setup code ...\r\nCKComponent *rootComponent = [MyCKRootComponent rootComponent:model context:context]; // have an error in the model and the component is nil\r\n    if (!rootComponent) {\r\n        Log(@\"-E- This is a criticial error. Could not build a root component for model %@\",model);\r\n        // suggested way to stop the flow? \r\n       // need to return \"nil\" root component\r\n    }\r\n   ....\r\n   return rootComponent;\r\n}\r\n```"}}
{"actor":{"display_login":"ocrickard"}}