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 way to get module of variable from an UndefVarError #25263

Closed
djsegal opened this issue Dec 24, 2017 · 6 comments · Fixed by #51979
Closed

Add way to get module of variable from an UndefVarError #25263

djsegal opened this issue Dec 24, 2017 · 6 comments · Fixed by #51979
Labels
domain:error messages Better, more actionable error messages Hacktoberfest Good for Hacktoberfest participants

Comments

@djsegal
Copy link

djsegal commented Dec 24, 2017

Repeat of Discourse Post:


From Post:

If you do:

cur_error = nothing 

try 
  foo(bar::Main.baz) = "Rambo"
catch tmp_error
  cur_error = tmp_error
end

which gives

> cur_error
UndefVarError(:baz)

> cur_error.var
:baz

The thing I'm kind of curious about is if there is a way to get the module that should have :baz in it (i.e. Main)?

@vchuravy
Copy link
Sponsor Member

Again please do not double post. Discourse is meant for questions like this and by double posting you are sending everyone two emails.

@vtjnash vtjnash reopened this Dec 24, 2017
@vtjnash
Copy link
Sponsor Member

vtjnash commented Dec 24, 2017

I agree - don’t double post. But this one seems like a good idea, and probably not bad as a first PR.

@djsegal
Copy link
Author

djsegal commented Dec 24, 2017

Won't double post in the future.

The reason for this one though is because:

  • it didn't get traction on Discourse
  • then i realized it's probably because it would have to be implemented.

Is this not a correct workflow?

(i.e. avoid making issues on github as long as possible. but do so once you realize it's the way to go?)

@djsegal
Copy link
Author

djsegal commented Dec 24, 2017

Also @vtjnash, what spec should I build this under?

Do you add a :mod field to UndefVarError that stores a symbol representation of the module?

// or do you just store the module object directly?

@vtjnash
Copy link
Sponsor Member

vtjnash commented Dec 24, 2017

it didn't get traction on Discourse

Also probably just slow for the holidays. This could have been opened straight as a feature request on github. Posting an update on Discourse to say that you had turned it into an issue would also be good (to try to avoid splitting any discussion, and avoid the appearance of double posting).

I recommend just storing the Module reference directly in a new field (and leave it uninitialized for local variables - or better yet store the Method)

@JeffBezanson
Copy link
Sponsor Member

avoid making issues on github as long as possible

+1 to what vtjnash said, and I'll add that I mostly read github issues so I'm more likely to see things here. I will never tell anybody not to open a github issue --- if an issue is inappropriate for whatever reason it is very quick and easy to close one.

@vtjnash vtjnash added Hacktoberfest Good for Hacktoberfest participants domain:error messages Better, more actionable error messages labels Apr 14, 2021
vtjnash added a commit that referenced this issue Oct 31, 2023
Record the 'scope' of the variable that was undefined (the Module, or a
descriptive word such as :local or :static_parameter). Add that scope to
the error message, and expand the hint suggestions added by the REPL to
include more specific advice on common mistakes:

  - forgetting to set an initial value
  - forgetting to import a global
  - creating a local of the same name as a global
  - not matching a static parameter in a signature subtype

Fixes #17062 (although more could probably be done to search for typos using REPL.string_distance and getting the method from stacktrace)
Fixes #18877
Fixes #25263
Fixes #35126
Fixes #39280
Fixes #41728
Fixes #48731
Fixes #49917
Fixes #50369
vtjnash added a commit that referenced this issue Nov 8, 2023
Record the 'scope' of the variable that was undefined (the Module, or a
descriptive word such as :local or :static_parameter). Add that scope to
the error message, and expand the hint suggestions added by the REPL to
include more specific advice on common mistakes:

  - forgetting to set an initial value
  - forgetting to import a global
  - creating a local of the same name as a global
  - not matching a static parameter in a signature subtype

Fixes #17062 (although more could probably be done to search for typos using REPL.string_distance and getting the method from stacktrace)
Fixes #18877
Fixes #25263
Fixes #35126
Fixes #39280
Fixes #41728
Fixes #48731
Fixes #49917
Fixes #50369
vtjnash added a commit that referenced this issue Nov 8, 2023
Record the 'scope' of the variable that was undefined (the Module, or a
descriptive word such as :local or :static_parameter). Add that scope to
the error message, and expand the hint suggestions added by the REPL to
include more specific advice on common mistakes:

  - forgetting to set an initial value
  - forgetting to import a global
  - creating a local of the same name as a global
  - not matching a static parameter in a signature subtype

Fixes #17062 (although more could probably be done to search for typos
using REPL.string_distance and getting the method from stacktrace)
Fixes #18877
Fixes #25263
Fixes #35126
Fixes #39280
Fixes #41728
Fixes #48731
Fixes #49917
Fixes #50369
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:error messages Better, more actionable error messages Hacktoberfest Good for Hacktoberfest participants
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants