This PR simplifies the code used to load tags from the home folder. In particular, it adds CodingKeyRepresentable conformance to Tag so that tags can be used directly as keys in a JSON-encoded dictionary without us having to jump through hoops to convert them from strings.
// Load tag colors from user/package preferences on disk.
263
result += tagColorOptions()
263
if let tagColors = try? loadTagColors() {
stmontgomery1 year ago
If there's an error thrown here should we log at least, while proceeding to run tests? (I see this is not really a behavior change from before this PR, but might be nice, still)
grynspan1 year ago
Maybe. I don't want to leak a dependency on Foundation out of that file, but we'd need to check for CocoaError(.fileNotFound) (or however it's spelt.)
stmontgomery1 year ago
Oh I figured it could just handle any error, not necessarily specific ones. Tag colors aren't mission critical, I wouldn't say, so any error that arises could just be noted but we continue to run tests
grynspan1 year ago
That wouldn't work because it throws an error if the user hasn't created a "tag-colors.json" file, which is obviously not a failure mode. Hence we'd need to special-case file-not-found errors.
stmontgomery1 year ago
Maybe separating out the "is there a colors file" and "parse said file" logic would make that easier? Seems like the
former could be non-throwing
grynspan1 year ago
That would require us to leak the Foundation dependency out in the form of returning an instance of Data? which, again, we want to avoid.
Since, as you said, tag colors aren't mission critical, we're probably overthinking it. :)
This PR simplifies the code used to load tags from the home folder. In particular, it adds
CodingKeyRepresentable
conformance toTag
so that tags can be used directly as keys in a JSON-encoded dictionary without us having to jump through hoops to convert them from strings.