Fix null argument handling in _uploadErrored function #223
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The build was failing with the error:
Element ERRORS is undefined in ARGUMENTSwhen the_uploadErroredfunction was called with a null value for theerrorsparameter.This occurred because when
invoke()is called with a Java null as a positional parameter (e.g.,javaCast("null", "")), CFML doesn't create an entry in the arguments scope for that parameter. The original code attempted to accessarguments.errorsdirectly, which threw an undefined error.Root Cause
When the test calls:
invoke(this, "_uploadErrored", ["photo", javaCast("null", ""), false])CFML doesn't populate
arguments.errorsbecause the second parameter is a Java null. Attempting to access it witharguments.errorsthrows:Element ERRORS is undefined in ARGUMENTS.Solution
Modified the
_uploadErroredfunction to safely handle null/missing parameters by:arguments.errorsexists usingstructKeyExists()before accessing itjavaCast("null", "")to ensure the parameter is always passedThis allows the
onUploadErrorcallback to receive all expected parameters and safely useisNull(arguments.errors)without errors.Changes
models/Component.cfc -
_uploadErroredfunction:// Before invoke(this, "onUploadError", { property: arguments.prop, errors: arguments.errors, // ❌ Fails when errors doesn't exist multiple: arguments.multiple }); // After local.invokeParams = { property: arguments.prop, multiple: arguments.multiple }; if (structKeyExists(arguments, "errors")) { local.invokeParams.errors = arguments.errors; } else { local.invokeParams.errors = javaCast("null", ""); // ✅ Explicitly handle missing parameter } invoke(this, "onUploadError", local.invokeParams);Testing
The failing test "should call onUploadError() if it exists when _uploadErrored is called" now passes because the
onUploadErrorcallback receives all expected parameters, includingerrorsas null, allowing the test component to safely useisNull(arguments.errors).Fixes build failure reported in issue.
Original prompt
Fixes #222
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.