Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PawelWozniak opened this issue Jan 17, 2024 · 7 comments
Labels
area:apex status: triaged These items have been triaged and are in the backlog type:bug

Comments

@PawelWozniak
Copy link
Contributor

PawelWozniak commented Jan 17, 2024

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
  1. 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.

Copy link

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.

@shetzel
Copy link

shetzel commented Jan 17, 2024

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 shetzel transferred this issue from forcedotcom/cli Jan 17, 2024
@peternhale
Copy link
Contributor

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

@peternhale peternhale transferred this issue from forcedotcom/salesforcedx-apex Jan 18, 2024
@peternhale
Copy link
Contributor

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

Copy link

git2gus bot commented Jan 19, 2024

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

@ChuckJonas
Copy link

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...

@PawelWozniak PawelWozniak changed the title Inconsistent error message during APEX compilation, for missing colon, between deploy and run Anonymous Apex Inconsistent error message during APEX compilation, for missing semicolon, between deploy and run Anonymous Apex Feb 28, 2024
@diyer
Copy link
Collaborator

diyer commented Apr 11, 2024

@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 diyer added the status: triaged These items have been triaged and are in the backlog label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:apex status: triaged These items have been triaged and are in the backlog type:bug
Projects
None yet
Development

No branches or pull requests

5 participants