salesforcedx-vscode icon indicating copy to clipboard operation
salesforcedx-vscode copied to clipboard

Inconsistent error message during APEX compilation, for missing semicolon, between deploy and run Anonymous Apex

Open PawelWozniak opened this issue 1 year ago • 7 comments

Summary

For the same code run as Anonymous Apex or deployed on class save to org, there are different error messages. This one from Anonymous run is misleading.

Steps To Reproduce

Having this apex code:

private static Contact createTestContact(Account acc) {
	Contact newContact = new Contact();
		newContact.AccountId = acc.Id;
		newContact.FirstName = 'Bob';
		newContact.LastName = 'Smith';
		newContact.Status__c = 'Active';
		newContact.Phone = '+49012345678';
		newContact.Email = '[email protected]';
		newContact.Academic_Title__c = 'Dr.';
		newContact.Gender__c = 'Male' // <-- It is missing semicolon here.
  
		insert newContact;
		return newContact;
}
  1. Create an apex class paste this code and try to save it to Salesforce. (I did that in VSCode). 2024-01-17_10h51_42

  2. Create anonymous apex file, paste it and run with command sf apex run --file xTemp.apex 2024-01-17_10h48_10

Expected result

In both cases I expect to get the error: "Unexpected token 'insert'." as the semicolon is missing before insert (in the line above).

Actual result

When code is run in Anonymous Apex I get the error: "Unexpected token 'private'." which refers to the whole block of the code. Then I am confused about what is wrong with this block. Need to do a deeper search.

System Information

{
  "architecture": "win32-x64",
  "cliVersion": "@salesforce/cli/2.23.20",
  "nodeVersion": "node-v20.10.0",
  "osVersion": "Windows_NT 10.0.22631",
  "rootPath": "C:\\Users\\pwozn\\AppData\\Local\\sf\\client\\2.23.20-50cd2d8",
  "shell": "cmd.exe",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 3.0.4 (core)",
    "@oclif/plugin-commands 3.1.0 (core)",
    "@oclif/plugin-help 6.0.9 (core)",
    "@oclif/plugin-not-found 3.0.7 (core)",
    "@oclif/plugin-plugins 4.1.14 (core)",
    "@oclif/plugin-search 1.0.10 (core)",
    "@oclif/plugin-update 4.1.7 (core)",
    "@oclif/plugin-version 2.0.11 (core)",
    "@oclif/plugin-warn-if-update-available 3.0.8 (core)",
    "@oclif/plugin-which 3.0.14 (core)",
    "@salesforce/cli 2.23.20 (core)",
    "apex 3.0.14 (core)",
    "auth 3.1.0 (core)",
    "data 3.0.13 (core)",
    "deploy-retrieve 2.2.12 (core)",
    "info 3.0.13 (core)",
    "limits 3.1.0 (core)",
    "marketplace 1.0.15 (core)",
    "org 3.2.0 (core)",
    "packaging 2.1.1 (user)",
    "schema 3.1.0 (core)",
    "settings 2.0.14 (core)",
    "sobject 1.0.7 (core)",
    "source 3.0.10 (core)",
    "telemetry 3.1.8 (core)",
    "templates 56.0.8 (core)",
    "trust 3.2.5 (core)",
    "user 3.2.0 (core)",
    "@salesforce/sfdx-scanner 3.20.0 (user)",
    "sfdmu 4.32.2 (user)",
    "sfdx-essentials 2.12.0 (user)",
    "sfdx-git-delta 5.33.0 (user)",
    "sfdx-hardis 4.25.0 (user)",
    "texei-sfdx-plugin 2.2.4 (user)"
  ]
}

Additional information

Side note for error message improvement. It would be useful actually to get an error "Missing semicolon at the end of the line 119". I think it is extremely uncommon in those days to have many statements in one line. Then it is safe to assume that when we have a line break and the line is not ended with a semicolon it is this syntax error.

PawelWozniak avatar Jan 17 '24 10:01 PawelWozniak

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.

github-actions[bot] avatar Jan 17 '24 10:01 github-actions[bot]

The CLI is just calling the apex-node library, so I'm going to transfer this issue to that repo. However, I suspect it's a difference in the server API being called and completely dependent on whatever that service returns.

shetzel avatar Jan 17 '24 23:01 shetzel

Going to transfer this to the salesforcedx-vscode repo. Seems to be related to the Apex language server.

peternhale avatar Jan 18 '24 21:01 peternhale

@PawelWozniak We will see what details I can find around these inconsistencies.

peternhale avatar Jan 18 '24 21:01 peternhale

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

git2gus[bot] avatar Jan 19 '24 13:01 git2gus[bot]

I'm finding that many errors just no longer return any error to vscode at all:

Summarize_Case_Comments_flow-meta_xml_—_AzureOpenAI

If I run the command manually: sfdx project:deploy:start --json

The expected array of errors get returned...

ChuckJonas avatar Feb 27 '24 17:02 ChuckJonas

@ChuckJonas, do you still see the following behavior? We had a regression in our older extension version where errors were not reported for some commands but we fixed it in the following release. Can you please let us know if you are still seeing this issue? Thank you!

I'm finding that many errors just no longer return any error to vscode at all:

diyer avatar Apr 11 '24 01:04 diyer