How Do I Debug A Large Server Action?

So I have a long Server Action. LIke at least 200 separate action steps.

Then I get an error message like this:

code: 0
file: "C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\db\Connection.php"
line: 111
message: "Object of class stdClass could not be converted to string"
trace: "#0 [internal function]: exception_error_handler(4096, 'Object of class...', 'C:\\Users\\anton\\...', 111, Array)↵#1 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\db\Connection.php(111): PDOStatement->bindParam(6, 'Object', 2)↵#2 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\modules\dbupdater.php(38): lib\db\Connection->execute('INSERT INTO `me...', Array, false, 'messages')↵#3 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(174): modules\dbupdater->insert(Object(stdClass), 'create_message')↵#4 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(138): lib\App->execSteps(Object(stdClass))↵#5 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(108): lib\App->execSteps(Array)↵#6 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\modules\core.php(92): lib\App->exec(Object(stdClass), true)↵#7 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(174): modules\core->condition(Object(stdClass), '')↵#8 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(138): lib\App->execSteps(Object(stdClass))↵#9 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(108): lib\App->execSteps(Array)↵#10 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(73): lib\App->exec(Object(stdClass))↵#11 C:\Users\anton\Dropbox\workshop-angel\dmxConnect\api\api\send_message_template.php(8): lib\App->define(Object(stdClass))↵#12 {main}"

Which refers to a line number in a file that I’ve never seen…

Does anyone have any tips on how to debug something like this?

My Server Action is send_message_template.php, and the trace has the line send_message_template.php(8). Is this any indication of where to look?

It looks like the error is in a database insert action step, one of the parameters is of the wrong type.

Thanks Patrick!

I found it in the end… I have a Set Value called “contact” and a database query also called “contact” and that is what upset things.

Is there any guide as to where to find the problem in your 200 line Server Action? Or do I just have to use trial and error, disabling things until I find what is causing them?

In ASP we return the action step also that caused the error, we could not manage to do this in PHP. But the stack trace helps to determine in which module/action the error occurred in and often helps us find the cause of the error.

Thanks for that help Patrick… so basically if we are really struggling to find the error then it is best to post it on here to get your input?

Maybe we can output more tracing and debug info when the debug is on @patrick?

2 Likes

The way the error messages appear in the browser developer tools is not helpful. Pasting the text into a text editor and replacing the #'s with returns makes it easier to read, with each part of the error on its own line. There are usually clues as to the error; eg in the current case:

image

Finally, and something that’s a matter of preference, I would always add a prefix to a query name - eg ‘qry_contact’, not just ‘contact’. I find this helps debugging and dealing with code generally. It’s certainly useful if you’re searching through text or are making global search/repaces, where searching for terms starting with sc_, mdl_ and qry_ etc will make things much easier. The example you’ve given in this thread makes a good case for it.

1 Like