Skip to content

Conversation

@Keno
Copy link
Member

@Keno Keno commented May 30, 2025

Similar to the existing world age hint for MethodError, this adds
a helpful message when an UndefVarError occurs because a binding
was defined in a newer world age than the code trying to access it.

The implementation checks if a binding that was undefined at the
error's world age is now defined in the current world, and displays:
"The binding may be too new: running in world age X, while current
world is Y."

Additionally, for all binding kinds, the error hint now notes when
the binding state has changed between the error's world and the
current world.

🤖 Generated with Claude Code

Similar to the existing world age hint for MethodError, this adds
a helpful message when an UndefVarError occurs because a binding
was defined in a newer world age than the code trying to access it.

The implementation checks if a binding that was undefined at the
error's world age is now defined in the current world, and displays:
"The binding may be too new: running in world age X, while current
world is Y."

Additionally, for all binding kinds, the error hint now notes when
the binding state has changed between the error's world and the
current world.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

# Get the current world's binding partition for comparison
curworld = tls_world_age()
cur_bpart = lookup_binding_partition(curworld, GlobalRef(scope, var))
Copy link
Member

@vtjnash vtjnash May 30, 2025

Choose a reason for hiding this comment

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

The printing world doesn't really have anything in common with the error world, especially in the REPL. Can Claud add the field to UndefVarError?

Copy link
Member Author

Choose a reason for hiding this comment

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

UndefVarError already has the field.

Copy link
Member Author

Choose a reason for hiding this comment

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

(See 5 lines prior)

Copy link
Member Author

Choose a reason for hiding this comment

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

The current world is just for the extra warning if the current kind is different from the old kind.

Copy link
Member

@vtjnash vtjnash May 30, 2025

Choose a reason for hiding this comment

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

Ah, great. I didn't realize we'd already done that. I assumed that Claude was just hallucinating it based on MethodError. I think we want get_world_counter() here though, not tls_world_age().

julia/base/errorshow.jl

Lines 347 to 349 in 44c3813

elseif hasmethod(f, arg_types) && !hasmethod(f, arg_types, world=ex.world)
curworld = get_world_counter()
print(io, "\nThe applicable method may be too new: running in world age $(ex.world), while current world is $(curworld).")

Copy link
Member Author

Choose a reason for hiding this comment

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

Claude thought so too, but I told it not to. I want to change the MethodError also, because otherwise there can be a TOCTOU issue with the hasmethod and the printing using different worlds. I think that's just confusing.

Copy link
Member

Choose a reason for hiding this comment

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

I thought hasmethod is a tls_world query these days to prevent the TOCTOU issue (looks like that is used incorrectly above). The methods listing query though is a latest world query, so it should try to be consistent with that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will make a separate PR to discuss that, but in any case, I think this should be tls_world_age

Keno added a commit that referenced this pull request May 30, 2025
This rolls up a couple of bug fixes with some tweaks to documentation
and AGENTS.md that came in useful getting the AI to do #58572.
Keno added a commit that referenced this pull request May 30, 2025
This rolls up a couple of bug fixes with some tweaks to documentation
and AGENTS.md that came in useful getting the AI to do #58572.
@vtjnash vtjnash added error messages Better, more actionable error messages backport 1.12 Change should be backported to release-1.12 labels May 30, 2025
Keno added a commit that referenced this pull request May 30, 2025
This rolls up a couple of bug fixes with some tweaks to documentation
and AGENTS.md that came in useful getting the AI to do #58572.
@Keno Keno merged commit 2e39f64 into master May 31, 2025
10 checks passed
@Keno Keno deleted the kf/undefvarerror-world-age-hint branch May 31, 2025 04:51
KristofferC pushed a commit that referenced this pull request Jun 2, 2025
Similar to the existing world age hint for MethodError, this adds
a helpful message when an UndefVarError occurs because a binding
was defined in a newer world age than the code trying to access it.

The implementation checks if a binding that was undefined at the
error's world age is now defined in the current world, and displays:
"The binding may be too new: running in world age X, while current
world is Y."

Additionally, for all binding kinds, the error hint now notes when
the binding state has changed between the error's world and the
current world.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Claude <[email protected]>
(cherry picked from commit 2e39f64)
@KristofferC KristofferC mentioned this pull request Jun 2, 2025
58 tasks
@KristofferC KristofferC removed the backport 1.12 Change should be backported to release-1.12 label Jun 4, 2025
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants