Skip to content

[BUG] Global variable not found #390

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

Open
vadim-96 opened this issue Feb 7, 2025 · 4 comments
Open

[BUG] Global variable not found #390

vadim-96 opened this issue Feb 7, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@vadim-96
Copy link

vadim-96 commented Feb 7, 2025

Describe the bug
If a global variable is set, the extension doesn't see it.

Steps To Reproduce
Steps to reproduce the behavior:

  1. Create __init__.robot with VAR ${WELCOME} Hello scope=GLOBAL
  2. Create test.robot file and write a simple test
  3. Add ${WELCOME} in your test
  4. See an error Variable '${WELCOME}' not found.robotcode(VariableNotFound) in VS Code

Desktop:

  • VS Code Version 1.97.0
  • RobotCode Version 0.108.1
  • OS: Windows 10
  • Python Version 3.13
  • RobotFramework Version 7.12
@vadim-96 vadim-96 added the bug Something isn't working label Feb 7, 2025
@gohierf
Copy link
Contributor

gohierf commented Feb 7, 2025

I believe this question has already been answered here and here.

@vadim-96 do you agree this is the same topic?

@vadim-96
Copy link
Author

vadim-96 commented Feb 7, 2025

This is the same topic, but it seems that it's a frequent problem. I don't think that static analyzers in other languages have the same behavior for global vars.

@vadim-96
Copy link
Author

By the way the global variables from Robot Framework are parsed without errors, why?
https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#automatic-variables

@gohierf
Copy link
Contributor

gohierf commented Feb 13, 2025

That is an interesting question. I don't think they are treated as global variables, they are presented as “automatic” variables. And I guess the decision was to add them for autocompletion, but there is no real check of their availability.

In some cases (see availability column) these variables are actually not there, for instance ${KEYWORD STATUS} should not be used outside a keyword. Interestingly enough, neither RobotCode nor Robocop warn about that. I guess this is worth an enhancement request (there it is for Robocop, I am waiting for @d-biehl input here to see if it is worth opening an issue regarding automatic variables for RobotCode).

Note that this case is a simple one, when the availability is "Everywhere" then there is no issue either. But for other availability like "Test Case", "Test Teardown", "Suite Teardown" and "User Keyword Teardown" I am not sure that RobotCode can actually work out if the variable is used in the correct situation, again because of static vs dynamic analysis. Nor would it make a lot of sense to require the user to define them in the variable section to set a default value to remove the warning (it does not seem to be good idea).

I guess we could have a warning like: "${TEST NAME}" variable is used in this keyword, but the keyword is used in a suite setup. (Although there could be a TRY/EXCEPT block, or something else, specifically to deal with this situation, so a warning could be a false positive...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

2 participants