-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
While using SugarUtils:File.append I accidentally left out the data argument, but I did supply some options:
SugarUtils::FIle.append('dir/filename', owner: 'owner', group: 'group')Since .append will write out any object which responds to #to_s, it wrote the options hash into the file, did not set owner/group on the file, and did this all silently.
What I had intended to write was:
SugarUtils::FIle.append('dir/filename', 'data_to_append', owner: 'owner', group: 'group')I think that this parameter pattern will very rarely be valid, so all of the write related methods should check it and raise an exception if:
- there are only 2 parameters pass to the method
- the data parameter is a Hash which contains only keys which are optional parameters
This change would mean that:
SugarUtils::FIle.append('dir/filename', owner: 'owner', group: 'group')but this would not, because it includes an unexpected key:
SugarUtils::FIle.append('dir/filename', owner: 'owner', group: 'group', unexpected_key: :value)This check would have caught my bug, and I think allow all of the correct calls to the method.
Reactions are currently unavailable