Skip to content

Commit 280f69d

Browse files
Add robust error handling to prevent REPL interference
- Wrap authentication in protective try-catch blocks - Add input error handling for readline() calls - Clean token input by removing whitespace/newlines - Add small safety delays to ensure proper I/O timing - Separate authentication success/failure logic - Add detailed error messages with token validation tips - Prevent REPL window issues during first authentication attempt 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent b58f7d8 commit 280f69d

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed

lib/LinearSolveAutotune/src/telemetry.jl

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,60 @@ function setup_github_authentication()
4444
println("🔑 Paste your GitHub token here (or press Enter to skip):")
4545
print("Token: ")
4646
flush(stdout) # Ensure the prompt is displayed before reading
47-
token = strip(readline())
47+
48+
# Add a small safety delay to ensure prompt is fully displayed
49+
sleep(0.05)
50+
51+
# Read the token input
52+
token = ""
53+
try
54+
token = strip(readline())
55+
catch e
56+
println("❌ Input error: $e")
57+
println("🔄 Please try again...")
58+
flush(stdout)
59+
sleep(0.1)
60+
continue
61+
end
4862

4963
if !isempty(token)
64+
# Wrap everything in a protective try-catch to prevent REPL interference
65+
auth_success = false
66+
auth_result = nothing
67+
5068
try
51-
# Test the token
52-
ENV["GITHUB_TOKEN"] = token
53-
auth = GitHub.authenticate(token)
69+
println("🔍 Testing token...")
70+
flush(stdout)
71+
72+
# Clean the token of any potential whitespace/newlines
73+
clean_token = strip(replace(token, r"\s+" => ""))
74+
ENV["GITHUB_TOKEN"] = clean_token
75+
76+
# Test authentication
77+
auth_result = GitHub.authenticate(clean_token)
78+
5479
println("✅ Perfect! Authentication successful - your results will help everyone!")
55-
flush(stdout) # Ensure success message is displayed
56-
return auth
80+
flush(stdout)
81+
auth_success = true
82+
5783
catch e
5884
println("❌ Token authentication failed: $e")
59-
println("💡 Make sure the token has 'public_repo' or 'Public Repositories' access")
60-
flush(stdout) # Ensure error messages are displayed
61-
delete!(ENV, "GITHUB_TOKEN")
85+
println("💡 Make sure the token:")
86+
println(" • Has 'public_repo' or 'Public Repositories' access")
87+
println(" • Was copied completely without extra characters")
88+
println(" • Is not expired")
89+
flush(stdout)
90+
91+
# Clean up on failure
92+
if haskey(ENV, "GITHUB_TOKEN")
93+
delete!(ENV, "GITHUB_TOKEN")
94+
end
95+
auth_success = false
96+
end
97+
98+
if auth_success && auth_result !== nothing
99+
return auth_result
100+
else
62101
attempts += 1
63102
if attempts < max_attempts
64103
println("🔄 Let's try again...")

0 commit comments

Comments
 (0)