Details
-
Improvement
-
Status: Closed
-
Normal
-
Resolution: Fixed
-
None
-
None
-
None
-
2
-
Language 2016-02-24, Language 2016-03-09, Language 2016-03-23
-
New Feature
-
The error message generated from the function asssert_type is now of the same high quality as the message produced for automatically type checked parameters.
Description
Type assertion and reporting could be greatly improved and also made consistent by fixing three minor things.
- The TypeAsserter methods takes a subject parameter that explains in what context the assertion takes place. It is often desirable to create this subject string from things in that context (i.e. format a string). Formatting strings that may or may not be used is however not a good practice since the formatting itself is resource consuming. Deferred formatting can be enabled by a) allowing an Array argument where the first element is a format string and the remaining elements are parameters to that format string, and b) allowing a block to be passed in the calls to the TypeAsserter. The block is called with the subject parameter as it's argument and returns a new subject.
- The TypeAsserter currently creates it's own "type mismatch" based on the subject and the compared types. It should instead utilize the TypeMismatchDescriber
- The Puppet function assert_type has it's own logic for asserting and printing errors. It should use the TypeAsserter.