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

Add hint for UndefVarError string macro errors #57529

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IanButterworth
Copy link
Member

@IanButterworth IanButterworth commented Feb 25, 2025

Master

julia> foo""
ERROR: LoadError: UndefVarError: `@foo_str` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
in expression starting at REPL[1]:1

This PR

julia> foo""
ERROR: LoadError: UndefVarError: `@foo_str` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Suggestion: You may be using the string macro form `foo""`, for which the expected `@foo_str` macro is not defined.
in expression starting at REPL[3]:1

todo:

  • Tests
  • Handle cmd macros too
julia> foo``
ERROR: LoadError: UndefVarError: `@foo_cmd` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
in expression starting at REPL[4]:1

@IanButterworth IanButterworth added needs tests Unit tests are required for this change error messages Better, more actionable error messages labels Feb 25, 2025
var = ex.var
m = match(r"@([a-zA-Z_][a-zA-Z0-9_]*)_str\b", string(var))
if m !== nothing && length(m.captures) == 1
print(io, "\nSuggestion: You may be using the string macro form `", m.captures[1], "\"\"`, for which the expected `$(var)` macro is not defined.")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(io, "\nSuggestion: You may be using the string macro form `", m.captures[1], "\"\"`, for which the expected `$(var)` macro is not defined.")
print(io, "\nSuggestion: You may be using the string macro form `", m.captures[1], "\"\"`, for which the necessary `$(var)` macro is not defined.")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error messages Better, more actionable error messages needs tests Unit tests are required for this change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant