go-edn / edn

Go implementation of EDN (Extensible Data Notation)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better handling for missing or badly formatted tag functions

mohkale opened this issue · comments

The format of a tag function is:

func foo(input T) (U, error) {
  // ...
}

More than once I've forgotten to include the error in the tags return type (making it just func(T) U). This package seems to silently fail when this happens, in my case returning the tag itself as a value in the unmarshald output. I kept thinking it was because I misspelled the tag, or something to that affect. Especially because this is the same behaviour it has for missing tags. A better default would be to consider missing tags an error or badly formulated tag functions as an error.

Yeah, this sounds like a reasonable addition – I'll be happy for any improvements here.

Okay @hypirion, so how would you suggest I proceed. I'd say supplying a badly formatted tag function to edn.AddTagFn should cause a panic. Referencing an undefined tag should be an error (instead of returning the tag itself). Thoughts?

@mohkale: I'll have a look at this this weekend, but from a quick look, edn.AddTagFn returns an error and checks that the error type is valid. I intend to verify that this is actually returned in cases where you forgot to add the error argument (it certainly looks like it is) and then add a MustAddTagFn that panics, akin to how regexp et al does it.

This seems rather straightforward, so if someone wants to work on this, feel free to ping me on this issue so that I don't do it myself :)

it certainly looks like it is

Hmmm... I've been using something like this function to bulk add tags but the wrong return type hasn't ever resulted in an error for me 😞. I'll double check now.

Update: No issues there, I must not have checked the error properly.

This seems rather straightforward, so if someone wants to work on this, feel free to ping me on this issue so that I don't do it myself

@hypirion I'm open to implementing this.