Replies: 3 comments 2 replies
-
I think it would be possible to implement something like this, but would probably require a lot of work and changes based on how the salt code is currently written. A large part of the problem stems from the design decision that the generic state and requisite arguments for the state compiler like
they had a structure that differentiated the arguments to the function from the arguments to the state compiler something like this:
or
The implementation could more easily avoid argument name conflicts as well as more easily do validation on the state compiler specific arguments. With the current structure the other issue with doing validation that extra arguments are not passed is with the encapsulation and separation of logic. The state compiler does not know or care about the arguments that are being passed to the state module functions; it just parses all the ones it knows and cares about and then passes the remaining arguments to state module function. Like you said the issue is with |
Beta Was this translation helpful? Give feedback.
-
Completely agreed. I think changing that would be the most theoretically sound fix, but I doubt it's worth the effort at this point.
I was thinking of something gradual, to catch typos in the most common states/modules first. Like I'm guessing that catching typos in def managed(..., **kwargs): to @handles_arguments('name', 'source', 'source_hash', ...)
def managed(..., **kwargs): then also change the code that calls it to catch any arguments that aren't part of either the requisite system or the args to |
Beta Was this translation helpful? Give feedback.
-
Some typos can be spotted by using a syntax highlighter https://salt.tips/text-editor-plugins-for-salt-states-and-yaml-jinja/ More complex checks can be addressed with a linter (maybe even with a custom check) https://salt-lint.readthedocs.io/en/latest/ |
Beta Was this translation helpful? Give feedback.
-
Consider this example:
There are two typos, and salt seems to completely ignore both of them. Has anybody thought about changing that so that either one of those would cause an error, or at least a warning?
I think this is somewhat complicated by all the usage of
**kwargs
because of all the shared args (likerequire
) that can be parsed in different places. It seems like it would be possible to catch those typos though somehow. Maybe add a decorator to functions that records which arguments each function parses as an attribute of the function, then the glue code could check if there are any leftover args that nothing is using?Beta Was this translation helpful? Give feedback.
All reactions