forcedotcom / salesforcedx-vscode

Salesforce Extensions for VS Code
https://developer.salesforce.com/tools/vscode
BSD 3-Clause "New" or "Revised" License
947 stars 404 forks source link

Using "SFDX: Launch Apex Replay Debugger With Current File" often throws error "Apex language server could not provide information about valid breakpoints" #5717

Open PieterJacob opened 1 month ago

PieterJacob commented 1 month ago

Summary

When trying to debug a .log file using the replay debugger, after right clicking on the .log file and choosing "SFDX: Launch Apex Replay Debugger With Current File", often an error is thrown: "Apex language server could not provide information about valid breakpoints". This happens to multiple developers in our team.

This issue is something that has already occurred for many months

Steps to Reproduce:

It is difficult to reproduce since it is unclear what causes this issue. But by describing the possible work around, it might clarify more what can cause this issue and how to fix it properly.

  1. Open a random debug file (.log) that was generated for the current project.
  2. Right click on the debug file and choose: "SFDX: Launch Apex Replay Debugger With Current File".
  3. After a certain loading time the error: '"Apex language server could not provide information about valid breakpoints" occurs and makes it impossible to debug. Reloading VS Code does not help.

Workaround

  1. After experiencing the error, for the current project, navigate to the folder that holds the apex.db file. In my case the location of this folder is at: .sfdx\tools\250\apex.db.

My assumption is that deleting the apex.db file and starting the replay debugger again creates a new apex.db file that is correctly in sync with the project, what might also explain the underlying issue, i.d. that the apex.db after a while gets out of sync...

Expected Result

There should occur no error and the Replace Debugger should start without any errors.

Actual Result

After right clicking on the .log file and choosing "SFDX: Launch APex Replay Debugger With Current File" an error occurs: "Apex language server could not provide information about valid breakpoints".

Additional Information

Below screen shows how to activate the Replay Debugger image Followed by error: image The workaround is to delete the apex.db file: image

Salesforce Extension Version in VS Code: v61.7 Salesforce CLI Version: @salesforce/cli/2.51.6 win32-x64 node-v20.15.0

OS and Version: Name: Windows 11 Edition: Windows 11 Enterprise Version: 23H2

VS Code Version: 1.92.0

svc-idee-bot commented 1 month ago

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

git2gus[bot] commented 1 month ago

This issue has been linked to a new work item: W-16457498

daphne-sfdc commented 1 month ago

Hi @PieterJacob, Thank you for filing this issue, and sorry for the inconvenience. Yes, this is a bug, and it's also a known issue. We have received it twice in the past, and as you stated as a workaround, both times the Apex Replay Debugger started working again after deleting the apex.db file. I filed a bug in my team's backlog.

In the meantime, can we get some info from you to help us reproduce it on our end? We would like the following info:

  1. org id of your org
  2. org shape (how many Apex classes, Apex test classes, custom objects, size of each Apex class/test class)
  3. How long is a typical Apex Replay Debugger session before you see that error and have to delete the apex.db? Is this value consistent across the developers on your team?
PieterJacob commented 1 month ago

Hi @daphne-sfdc, Thank you so much for taking your time and responding to this issue. See below for my input regarding your questions.

1. Org Id of your org This issue seems org unrelated. Like mentioned, this issue occurs for everyone in our team and for each newly created scratchOrg.

2. Org shape (how many Apex classes, Apex test classes, custom objects, size of each Apex class/test class) We have around 2500+ classes in our code base, 400 of these calsses are test classes. We have around 250 custom objects (including custom metadata types and custom settings).

3. How long is a typical Apex Replay Debugger session before you see that error and have to delete the apex.db? Is this value consistent across the developers on your team? Also this seems unrelated. It seems to happen for every .log file. The last example I could find was a debug file of around 2mb where the issue occurred.

daphne-sfdc commented 1 month ago

Hi @PieterJacob, Thank you for providing the above details. I tried creating a project with 2400 Apex classes and 400 Apex test classes, but I was unable to reproduce your issue by running Apex Replay Debugger on that project. Our next step would be to ask you to share a zip file of your project and the credentials of your scratch org with us, but for security reasons, we don't work with credentials via unsecured channels like Github issues or email.

Can you file an official Salesforce support ticket and route that ticket to us, the IDE Experience Team? We'll continue working with you on this issue via the Investigation. Thank you.

diyer commented 3 weeks ago

Hi @PieterJacob, are you still seeing this issue?

PieterJacob commented 3 weeks ago

Hi @daphne-sfdc and @diyer,

Sorry for my late response. The issue still occurs and I think that I now have a better understanding when the issues occurs. I noticed that when working on the same branch and scratchorg, and once I had removed the apex.db file the issues were resolved and I could create numerous new debug files and debug without the error occurring.

But... once I created a new branch and scratchorg and loaded my first debug file the error appeared again straight away. My colleagues also confirmed this. Important to add is that the the branch switch potentially causes a source code difference, since new classes and objects were added in the previous branch.

So it seems that the error is likely to show when you switch to a new branch and scratchorg - and possibly new objects such as classes and SObjects had been added in the previous branch - and start a new debug session. Hope this new insight helps to solve the issue.

Peter,

daphne-sfdc commented 3 weeks ago

Hello @PieterJacob,

I tried creating a new branch and new scratch org, then running Apex Replay Debugger on a file only present in that branch and scratch org. I then switched to a branch and scratch org without the file that I ran the ARD on, and used the log generated from the first run to run ARD on the second branch and scratch org. Despite the file not being present, I was still not seeing the error that you're getting.

In this week's release v61.10.0, our team added additional telemetry to Apex Replay Debugger to aid in diagnosing issues such as yours. Can you please update your Salesforce Extensions for VSCode to the latest version and rerun the Apex Replay Debugger to get the error? And also, can we get your machine ID so that we can use it to find your info in our telemetry? (Please email the machine ID to us at svc_idee_bot@salesforce.com instead of posting it in a public Github issue.)

diyer commented 2 weeks ago

@PieterJacob we will need your help in providing details that @daphne-sfdc requested above.

mnunezdm commented 2 weeks ago

Hello!

I'm also experiencing this issue, in my case, I have the sensation that is related to rapid changes in apex classes, for example changing branches that have a lot of changes between them

In our case we have a lot of classes, more than 7K

How do you get the machine id?

PieterJacob commented 2 weeks ago

@daphne-sfdc, Thanks for your answer. I will update my cli and provide the information as soon as I receive the same error again, I will ask my colleagues as well.

Now do I get my machine Id?

peternhale commented 2 weeks ago

@PieterJacob I recommend using the Salesforce CLI Id. The same value is sent in telemetry and it is easy to discover.

run sf telemetry and the output will look like this

sf telemetry
Telemetry is enabled.
Telemetry tmp directory is .......
Telemetry cache directory is ........

Salesforce CLI ID is 7e...................................b1.

capture the hexadecimal string value for Salesforce CLI ID and email it to the address noted earlier.

daphne-sfdc commented 2 weeks ago

Hi @PieterJacob and @mnunezdm,

What is your current value in the Salesforcedx-vscode-apex › Java: Memory setting? (If it's a blank value, the default is 512MB.)

If you have a blank value or lower, can you try increasing your memory allocation for the Apex Language Server to 1024 and see if that resolves the issue?

PieterJacob commented 1 week ago

@daphne-sfdc,

Thanks for the tip. The value was blank and I changed it to 1024. I'll make sure to test this in the upcoming week and keep you posted about my experiences regarding debugging.

PieterJacob commented 1 week ago

@daphne-sfdc,

I updated the value of Salesforcedx-vscode-apex › Java: Memory to 1024, but unfortunately, as soon as I created a new branch and scratch org, bam! I received the error again.

It really seems that when you switch from one branch to the other and the new branch contains a reasonable amount of object differences, that it is more likely to have to error to occur.

daphne-sfdc commented 1 week ago

Hi @PieterJacob, Sorry to hear that the workaround didn't work.

We're currently tracing back the error message in our codebase. To help us identify the correct path, can you please provide your Salesforce CLI ID by running sf telemetry in your Terminal as @peternhale suggested in his earlier message? Please email it to us at svc_idee_bot@salesforce.com.

PieterJacob commented 1 week ago

@daphne-sfdc,

Thanks a lot. I have just send svc_idee_bot@salesforce.com an email with my Salesforce CLI Id. Hope this helps, thanks.

Peter,

daphne-sfdc commented 1 week ago

@PieterJacob We found this old issue where the error that you're getting is caused by the presence of both a static and non-static variable of the same name in the same scope. Using the code in the image below (image taken from the thread of that old issue), I was able to reproduce the issue when running Apex Replay Debugger from the anonymous Apex file. image

Can you please verify that you don't have both a static and non-static variable of the same name in your code?

daphne-sfdc commented 1 week ago

Hi @PieterJacob,

Another question: In a previous message I saw you wrote "The last example I could find was a debug file of around 2mb where the issue occurred."

From that statement, I was wondering: What is the size of the Apex classes that you are running the Apex Replay Debugger on? I'd like to get an approximate idea of the number of lines of code that you have in your Apex classes.

daphne-sfdc commented 1 week ago

@PieterJacob Two more things:

  1. Can you please update your extensions and CLI to the latest version if you haven't done so already?
  2. We want to ensure you have telemetry enabled in the following 3 places: a. Set Telemetry: Telemetry Level in VSCode settings to all. b. Check the box for Salesforcedx-vscode-core > Telemetry: Enabled. c. Type sf telemetry in your Terminal and make sure you see the "Telemetry is enabled" message.
PieterJacob commented 1 week ago

@daphne-sfdc, I highly doubt we have classes in our system that both have a static and instance specific variable that share the same name, I would have expected that the compiler would scream at you in this instance. Besides, I don't know a way to check this other than looking over all classes individually.

Regarding our class sizes. We try to keep classes small and concise. I would say by average classes have no more than 1000 lines, with an average of 200 lines.

Ill make sure to update my CLI version. Thanks.

daphne-sfdc commented 1 week ago

Hi @PieterJacob, One more request: Please do the following steps:

  1. Go to the Output Tab with Apex Language Server for the dropdown.
  2. Clear the Output Tab.
  3. Launch the Apex Replay Debugger to get the "Apex language server could not provide information about valid breakpoints" error again.
  4. Close the error popup.
  5. Go back to the Output Tab with Apex Language Server for the dropdown.
  6. Send us the stack trace from the Output tab.

Here's a short video of how to do the above instructions:

https://github.com/user-attachments/assets/627a2afc-3e6b-41de-96e7-3abb60c02cfa

github-actions[bot] commented 4 days ago

This issue has not received a response in 3 days. It will auto-close in 2 days unless a response is posted.

diyer commented 3 days ago

@PieterJacob Thank you for your patience but we need one last thing from your end to try. Can you please refer to Daphne's comment above and share the contents of your output tab?