Skip to content

Should conversion functions return nil on nil input? #63

@vincentjames501

Description

@vincentjames501

If we supply nil to a conversion function, it throws an AssertionError

(csk/->kebab-case-keyword nil)
Execution error (AssertionError) at camel-snake-kebab.core/->kebab-case-keyword (core.cljc:21).
Assert failed: (clojure.core/not (clojure.core/nil? s__20671__auto__))

(cske/transform-keys csk/->kebab-case-keyword {nil "bar"})
Execution error (AssertionError) at camel-snake-kebab.core/->kebab-case-keyword (core.cljc:21).
Assert failed: (clojure.core/not (clojure.core/nil? s__20671__auto__))

We had an issue in production where this happened w/ some unexpected input and since it is an Error and not an Exception some things we're not handled properly.

Does it make sense to return nil on nil input? This feels a bit more idiomatic clojure usage to me.

Error : An Error “indicates serious problems that a reasonable application should not try to catch.”
Exceptions : An Exception “indicates conditions that a reasonable application might want to catch.”

At the very least throwing IllegalArgumentException or something may be better than an AssertionError?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions