Plugin Builder - Action - Action Code reports error

Building a plugin, creating an action and adding the action code is consistently resulting in the action code getting this error

Screen Shot 2025-01-02 at 2.41.39 PM

The error is falsely being reported…I’ve tested this by adding action codes from other working plugins and the error gets reported, but in the other plugin it does not.

Also, the plugin action code reporting the error actually runs and works properly, the only issue is the false error makes it impossible to save the new version.

No matter what actions that work without error reported are added in now, the error is reported. Even actions from the same plugin that do not show errors, show errors if copy and paste into new action action code block.

Yeah, that message can be legit, but sometimes it’s just a formatting issue. Bubble’s code parser is rather finicky. In the snippet below, I’m just adding a space before the first curly brace…

function-formatting

It’s been that way forever. :man_shrugging:

3 Likes

it’s one of the many quirks of plugins in bubble: your code must be wrapped by function (properties, context){ } but that’s actually a syntax error in js.

3 Likes

@sudsy @dorilama please check out the video of what I am experiencing. It doesn’t seem to be anything related to the plugin builder being finicky or quirky.

I’ve tried to add extra spaces, remove all spaces between the first curly brace and it doesn’t change things. I’ve also ensured it is wrapped by function (properties, context){ }

In the video you will notice the return values section is completely absent, and I’m not sure if that has anything to do with it.

But in my testing before reporting the bug, I copied code from other plugins of mine that don’t have the error, and pasted into a new plugin or the plugin which the bug first was spotted and the error shows for those. Not sure why the same code works and has no error in one plugin but in another it would. I also copied working code from other actions of the same plugin and the same thing, code without the error from another action will produce the error when pasted into a new action in the same plugin.

This is the code I tested with in the video…please let me know if this code has wrong formatting or is an issue in how it is wrapped.

async function (properties, context) {
    try {
        const primaryColor = properties.primary_color;
        if (!/^#[0-9A-F]{6}$/i.test(primaryColor)) {
            throw new Error("Invalid primary color. It must be a hex color code (e.g., #6200EE).");
        }

        // Helper function to convert HEX to RGB
        function hexToRgb(hex) {
            const bigint = parseInt(hex.slice(1), 16);
            return [(bigint >> 16) & 255, (bigint >> 8) & 255, bigint & 255];
        }

        // Convert primary color to RGB
        const primaryColorRgb = hexToRgb(primaryColor);

        // Format the RGB value as a string
        const primaryColorRgbString = `rgb(${primaryColorRgb.join(",")})`;

        // Return the result
        return {
            primary_color: primaryColorRgbString
        };
    } catch (error) {
        console.error("Error in plugin action:", error);
        return {
            primary_color: "Invalid color"
        };
    }
}

Trying to debug with ChatGPT using simple questions derived from the error message.

Does this script have more than 2,000,000 characters?

No, the script provided does not have more than 2,000,000 characters. It is relatively small and concise, consisting of only a few hundred characters at most. It is well within the character limit set by the error. You should be able to save and use this script without any issues related to character count.

Is this script wrapped by function (properties, context){ }

Yes, the script is correctly wrapped by async function (properties, context) { }. This ensures that it adheres to the required structure for a plugin action or function in systems that use this format, such as plugin development in certain platforms.

Can the script be interpreted as javascript?

Yes, the script can be interpreted as JavaScript. Here’s why:

  1. Proper Syntax: The script uses valid JavaScript syntax, including proper use of functions, variable declarations, error handling, and return statements.
  2. Wrapped in a Function: The script is correctly wrapped with async function (properties, context) { }, which is a valid JavaScript function definition.
  3. No Extraneous Characters: The script contains no extraneous characters or malformed syntax that would prevent it from being parsed as JavaScript.
  4. Complies with JavaScript Standards: The code adheres to modern JavaScript ES6+ standards, including the use of async/await, template literals, and modern function definitions.

If there is an issue with interpretation, it would likely not be due to the syntax or JavaScript validity but possibly due to platform-specific constraints or errors elsewhere in the implementation.

I’m pretty much at a loss of explanation except that there is a bug.

Is anybody else experiencing this bug with the plugin editor?

So I think the bug is related to the fact that Return Results section is not present when creating a new action, even after adding code…and that the editor is buggy or rather finnicky or quirky.

If I take the same code but do not use my own wrapping and just paste it into the middle of the pre-configured wrapping, it doesn’t show an error…but still, the returned results section is empty and I can not find a way to add them.

BTW, this test in this video is from a different account for a different plugin, so seems like the bug is affecting the system, or at least not just my account as it may not be system wide but maybe clustered.

@dorilama @sudsy are you guys experiencing the issue of the returned values section not present or correctly structured code getting the error applied?

EDIT

I’ve seen my error with not selecting the action type as server side which causes the return values section to not be present.

Still concerned about the error message appearing unnecessarily though, despite being able to find a workaround.

If you look REALLY closely, you’ll see you’ve misquoted the error message. There is no space between the word function and the left parenthesis. Remove that space, and I think the message will disappear.

As @dorilama said, there are quirks, and they have nothing to do with valid or invalid JS syntax (unfortunately).

1 Like

there is a deterministic way to answer this kind of question…

anyway it’s not about return values, it’s about the exact string that needs to wrap your code, like @sudsy said

1 Like

Thanks @sudsy and @dorilama

This is why I still don’t want to learn to code…I can’t look so closely and spot these things myself.

I can see now the space between the word function and left parenthesis in my non-working code.

What I had been doing to get around it was to just use Bubble’s prebuilt wrapping…now I’ll be able to spot check the space instead.

1 Like

This topic was automatically closed after 14 days. New replies are no longer allowed.