While working on other issue, I noticed a bit of inconsistency in the file_check_directory() function. It may be (optionally) called with a form element name, to file any errors against that element. Currently, there are three instances of form_set_error() inside that code. One of these is called conditionally, only if file_check_directory() is used on a form element, other two are called always (in the independent-of-any-forms usage too).

Currently, this is not causing any trouble, because (luckily) form_set_error() do literally nothing if called with a NULL argument. But it might change in the future. Also the inconsistent code inside file_check_directory() looks quite puzzling at first glance.

So I think that it would be still nice to clean this up, even if it was just for code readability. The attached patch is standardizing on the conditional call method, which I believe is more robust (although currently saves us just a function call with one other conditional inside). Other possibility might be to remove also the existing conditional to standardize on unconditional calls (thus relying on form_set_error() behavior with NULL, which will then need to be documented).

Since nothing is currently broken, this issue is 'minor' ;)

Comments

pfrenssen’s picture

Status: Needs review » Reviewed & tested by the community

indeed no functional change but a small improvement in code consistency

Status: Reviewed & tested by the community » Needs work

The last submitted patch, file-form-errors.patch, failed testing.

pfrenssen’s picture

Status: Needs work » Needs review
StatusFileSize
new1.77 KB

Strange, the patch applies cleanly here. I rolled a new patch, let's see if this is more appetizing to the test bot. The code has not changed.

Status: Needs review » Needs work

The last submitted patch, 202935-3-inconsistent-form-element-check.patch, failed testing.

pfrenssen’s picture

Status: Needs work » Closed (works as designed)

I don't see the point in this any more.