How to debug an error

Hiyas,

Just wondering what the best way is to troubleshoot this error? I’ve pored over the .ps1 code and can’t spot where the error is. I’ve set the logging to debug (from the admin page) and downloaded the logs, can’t see in there anything that jumps out…

Dashboard .ps1 page shows this on load…

Imgur

Log from the dashboard ‘Log’ tab in the admin pages…

Mar 29, 2022 10:31 AM An error occurred: The term '$JobName' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Endpoint: eb79b775-5353-4877-ba96-a15adcb4d972
Session: 3eaf9ad4-afe8-4392-904e-9dc98a7e220c, User: DOMAIN\First.Last
Stack Trace:
- The term '$JobName' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. at eb79b775-5353-4877-ba96-a15adcb4d972:15
- eb79b775-5353-4877-ba96-a15adcb4d972:5

It looks like the $JobName variable is accidentally attempting to be called as like a function or something but I can’t see anywhere like that in the .ps1 page code.

Is there an even more verbose way to log what’s happening in the page, perhaps get the script line where this error is thrown?

Cheers!
Steve.

The stacktrace might provide some more insight.

The error is happening at line 15 of the endpoint eb79b775-5353-4877-ba96-a15adcb4d972
This is being called from line 5 of the endpoint eb79b775-5353-4877-ba96-a15adcb4d972

If you provide IDs to your components, then the endpoint listed in the stack trace won’t be a GUID so that might help track it down.

1 Like

Brilliant, found the endpoint, and found a missing backtick ` character, arrrghhhh you sneaky backtick

My error:

Show-UDToast -Message "cache:$(`$JobName)ButtonText = $(Get-Item -pspath "cache:$($JobName)ButtonText")" -Duration 5000

Resolved:

Show-UDToast -Message "cache:`$(`$JobName)ButtonText = $(Get-Item -pspath "cache:$($JobName)ButtonText")" -Duration 5000

Thanks for that tip, Adam

2 Likes