`$_ERROR` Not populating properly in server actions

I have a try/catch in my server action where I want to show the $_ERROR.
This variable seems to not populate properly anymore. It doesn't show the value when I try to log $_ERROR.

Reproduce

  1. Create a try/catch
  2. Put a query in the try, don't set up any settings inside query so it'll fail
  3. Add a response step in teh catch where you add the $_ERROR to the 'text' property
    Should look like this:

Result: empty response CleanShot 2024-04-29 at 17.36.22

Now add a string next to the error:

It shows the full string and the actual error message: CleanShot 2024-04-29 at 17.37.07

This is very annoying as we're using the logging extension from @tbvgl
We have MANY server actions where we're catching the error like this:
CleanShot 2024-04-29 at 17.38.08

Which no longer works as a byproduct of whatever is going on here.

Extra debugging information:
When you use a value step to catch the error like so:

Then this value is not set (which I do expect to happen since it's in my catch. Instead of that I get:

However! If you add a string again, it does behave as expected and shows me what's in the 'catch' block:


CleanShot 2024-04-29 at 17.40.44

Bump, this is making a lot of our logs useless which leads to being partially blind on production :frowning:

I assume you use NodeJS, try the following update

server.zip (1.4 KB) Unzip in lib folder

Thanks @patrick
Yes NodeJS, this Partially fixes it.
It works in the response step, but I still can’t access it as a variable how I used to do it:

For example in the logging extension:


CleanShot 2024-04-30 at 15.55.33@2x

It does work if I add a string again like before:

Same behaviour for a ‘set value’ step:

But then I add a string before the $_ERROR binding again and it works:

The problem is that in JavaScript an Error object is not serializable in JSON and is ignored. I added an extra replacer function for the JSON output that converts the Error object to a string. Easiest way to output an Error is by using the toString() formatter. I will investigate for some other solutions.

Hmm did something change though in your code? I’m confident it was working this way before

Bump. Still having problems with this

@patrick
Bit of extra info.

As far as I'm aware the $_ERROR variable set by Wappler can be a javascript object, OR a javascript error object.

If it's an error object, the following happens

  1. If I try to set a value like
error_raw = {{$_ERROR}}` 

I get

{
  "status": "500",
  "message": "A server error occurred, to see the error enable the DEBUG flag."
}

Which is really not desirable as this is now breaking the rest of the server action (even though this is already in a CATCH)... So just by setting a variable in the catch, the other thing won't run.
Visual:

  1. If I set a values like:
    CleanShot 2024-06-14 at 15.42.17
    I get:
{
  "error_toJSON": "{}",
  "error_toString": "Error: dbconnector.single: sql is required.",
  "something_else": "hi"
}

Which is better as it doesn't break it... but the issue here is that depending on the type of error (normal object or javascript error object) I need a different formatter.

Plus we need to add formatters to all the places where we're just using the $_ERROR as is.
It would be a much better solution if the logic to either stirngify or .toString() is done where you are currently setting the $_ERROR variable in the first place

I swear that this was never an issue before, something must have changed :frowning: - maybe you can find that change and revert it...

Found the issue, the tryCatch action was still setting the original Error object on the scope.

Here an update: core.zip (2.1 KB) unzip to lib/modules.

1 Like

Fixed in Wappler 6.7.1

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.