title: Golang best practices: empty array response or error?
body: <p>What are best practices in terms of error handling for a function that accepts slice of objects and returns another slice of objects (ideally of same length as input array) along with error as follows:</p>
  
  <pre><code>func ([]interface{}) ([]interface{}, error)
  </code></pre>
  
  <p>One way is whenever you get an error for processing one of the objects in a slice, you return an error response, but that way at the receiving function, if you don't discard all slice elements, error response becomes of little use merely telling us that processing of one of the elements or all failed. Another way is you return an error when none of the elements get processed but again this is of little use I feel. One more way is you don't include error as return object and instead with every slice element struct, have it's own error object as a composite so you can send elementwise error as output.</p>
  
  <p>The best way obviously depends on the particular scenario, however, I want to know if there are any best practices people follow or any design patterns around this problem.</p>
  
  <p>PS: This was one of the closest questions, however since its accepting single object as input, not very relevant:
  <a href="https://stackoverflow.com/questions/24852784/return-empty-array-or-error">Return empty array or error</a></p>