duct-framework / core

The core library of the Duct framework
75 stars 21 forks source link

Add an exception for when a module key isn't a function #32

Closed kwrooijen closed 4 years ago

kwrooijen commented 4 years ago

Problem

Currently when adding an init-key outside of :duct.profile/base, which is not a function (takes a config, returns a config), you get the following error.

Execution error (AssertionError) at integrant.core/prep (core.cljc:399).
Assert failed: (map? config)

This is not very helpful, because the end user will most likely assume that they made a typo in their config. I also believe new users struggle with understanding the difference between regular init-key and module init-keys. Which is why they put keys in the wrong place.

Solution

Add validation to the fold-modules function, checking that each module key is an fn. If not, throw a custom error which is more understandable than the default.

Notes

I'm sure the exception message / docstring can be improved on. Also, should a private function have a docstring?

kwrooijen commented 4 years ago

@weavejester How is this?

kwrooijen commented 4 years ago

@weavejester ping

weavejester commented 4 years ago

Sorry about the delay - I've been trying to get through my backlog of PRs and issues.

This looks fine, but could you add a small test in in order to prevent any regressions?

teodorlu commented 4 years ago

I appreciate this getting some love, thanks kwrooijen and weavejester! :pray: :heart:

kwrooijen commented 4 years ago

@teodorlu Thank you for the reminder @weavejester added some tests

kwrooijen commented 4 years ago

@weavejester applied your requested changes / responded