error-stack: pattern for attaching to a bunch of errors? #1982
Replies: 1 comment
-
Hi, @bjchambers, and sorry for not responding for this long. I missed this question 😞 Typically, if you find yourself adding the same attachments over and over again it typically is a sign that those functions should be moved into a separate function and add the attachments to that function call. Ideally, you want to attach outside of the actual functions. For example, if you have a function to create a file at a given path The above is not always possible so one solution would be to create a function that takes a Hope this will still help you, excited to hear what you have ended up with! 🙂 |
Beta Was this translation helpful? Give feedback.
-
A common pattern I see is having a method that attempts to read a file, and wanting to attach the file to any error within the method. I haven't found a good way to avoid duplicating things, and this often ends up with something like:
Sometimes there may be two or three printables that I wish to add. I find myself wishing I could register something as a printable to be attached if/when an error happens (lazily would be ideal, since often it may need to be cloned so the error can own it). Is there a pattern for this? Does anyone have ideas on how to avoid the repetition?
Beta Was this translation helpful? Give feedback.
All reactions