Skip to content

Conversation

Copy link

Copilot AI commented Oct 23, 2025

Problem

The build was failing with the error: Element ERRORS is undefined in ARGUMENTS when the _uploadErrored function was called with a null value for the errors parameter.

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 access arguments.errors directly, which threw an undefined error.

Root Cause

When the test calls:

invoke(this, "_uploadErrored", ["photo", javaCast("null", ""), false])

CFML doesn't populate arguments.errors because the second parameter is a Java null. Attempting to access it with arguments.errors throws: Element ERRORS is undefined in ARGUMENTS.

Solution

Modified the _uploadErrored function to safely handle null/missing parameters by:

  1. Building the invoke parameters struct explicitly in a local variable
  2. Checking if arguments.errors exists using structKeyExists() before accessing it
  3. If it doesn't exist, explicitly setting it to javaCast("null", "") to ensure the parameter is always passed

This allows the onUploadError callback to receive all expected parameters and safely use isNull(arguments.errors) without errors.

Changes

models/Component.cfc - _uploadErrored function:

// 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 onUploadError callback receives all expected parameters, including errors as null, allowing the test component to safely use isNull(arguments.errors).

Fixes build failure reported in issue.

Original prompt

This section details on the original issue you should resolve

<issue_title>Builds are failing</issue_title>
<issue_description> !! should call onUploadError() if it exists when _uploadErrored is called (27 ms)
-> Error: Element ERRORS is undefined in ARGUMENTS.
-> at /home/runner/work/cbwire/cbwire/models/Component.cfc:1010

        -> at /home/runner/work/cbwire/cbwire/models/Component.cfc:904 

        -> at /home/runner/work/cbwire/cbwire/models/Component.cfc:902 

        -> at /home/runner/work/cbwire/cbwire/models/Component.cfc:1169 

        -> at /home/runner/work/cbwire/cbwire/models/CBWIREController.cfc:108 </issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #222


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@grantcopley
Copy link
Collaborator

@copilot It's only happening on ACF engines btw

Copilot AI changed the title [WIP] Fix handling of undefined element ERRORS in upload process Fix null argument handling in _uploadErrored function Oct 23, 2025
Copilot AI requested a review from grantcopley October 23, 2025 21:37
Copilot finished work on behalf of grantcopley October 23, 2025 21:37
Copy link
Author

Copilot AI commented Oct 23, 2025

@copilot It's only happening on ACF engines btw

Got it - ACF handles null arguments in invoke() differently than Lucee/BoxLang. The fix in commit 16b6708 checks for the parameter's existence before accessing it, which should resolve the ACF-specific issue where arguments.errors isn't populated when a Java null is passed positionally.

Copilot finished work on behalf of grantcopley October 23, 2025 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants