-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Fix startup when history file is bad #59418
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
Merged
IanButterworth
merged 6 commits into
JuliaLang:master
from
IanButterworth:ib/bad_history
Sep 3, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
235430d
Fix startup when history file is bad
IanButterworth fec6bf8
add test
IanButterworth 3dbc352
debug windows failure
IanButterworth a2fc5b0
more debug
IanButterworth 9a606a3
windows tryfix
IanButterworth fc0a9b1
remove debug
IanButterworth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
# Test that interactive mode starts up without error when history file is bad | ||
|
||
using Test | ||
|
||
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test") | ||
isdefined(Main, :FakePTYs) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "FakePTYs.jl")) | ||
import .Main.FakePTYs: with_fake_pty | ||
|
||
@testset "Bad history file startup" begin | ||
mktempdir() do tmpdir | ||
# Create a bad history file | ||
hist_file = joinpath(tmpdir, "repl_history.jl") | ||
write(hist_file, "{ invalid json content\nmore bad content\n") | ||
|
||
julia_exe = Base.julia_cmd()[1] | ||
|
||
# Test interactive Julia startup with bad history file | ||
with_fake_pty() do pts, ptm | ||
# Set up environment with our bad history file | ||
nENV = copy(ENV) | ||
nENV["JULIA_HISTORY"] = hist_file | ||
|
||
# Start Julia in interactive mode | ||
p = run(detach(setenv(`$julia_exe --startup-file=no --color=no -q`, nENV)), pts, pts, pts, wait=false) | ||
Base.close_stdio(pts) | ||
|
||
# Read output until we get the prompt, which indicates successful startup | ||
output = readuntil(ptm, "julia> ", keep=true) | ||
# println("====== subprocess output ======") | ||
# println(output) | ||
# println("====== end subprocess output ======") | ||
|
||
# Test conditions: | ||
# 1. We should see the invalid history file error | ||
has_history_error = occursin("Invalid history file", output) || | ||
occursin("Invalid character", output) | ||
@test has_history_error | ||
|
||
# 2. We should NOT see UndefRefError (the bug being fixed) | ||
has_undef_error = occursin("UndefRefError", output) | ||
@test !has_undef_error | ||
|
||
# 3. We should see the "Disabling history file" message if the fix works | ||
has_disable_message = occursin("Disabling history file for this session", output) | ||
@test has_disable_message | ||
|
||
# Send exit command to clean shutdown | ||
if isopen(ptm) | ||
write(ptm, "exit()\n") | ||
else | ||
@warn "PTY master is already closed before sending exit command" | ||
end | ||
|
||
# Read any remaining output until the process exits | ||
try | ||
read(ptm, String) | ||
catch ex | ||
# Handle platform-specific EOF behavior | ||
if ex isa Base.IOError && ex.code == Base.UV_EIO | ||
# This is expected on some platforms (e.g., Linux) | ||
else | ||
rethrow() | ||
end | ||
end | ||
|
||
# Wait for process to finish | ||
wait(p) | ||
|
||
@test p.exitcode == 0 | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.