[ANN] TheFix.jl for the REPL

I’m happy to announce TheFix.jl for the most common errors encountered in the REPL. Some syntactical or typographical errors wouldn’t have been made in a perfect world; this package tries to fix them for you. Here are some examples:

EDIT: The gif shows v0.1.1. In v0.2, the macro TheFix.@safeword now takes two arguments: the safe word and a Boolean variable to indicate whether or not the user requests confirmation. The readme has updated examples.

28 Likes

remind me of https://github.com/nvbn/thefuck

4 Likes

Yep, but tried to be less offensive about the name :slight_smile: You can choose your own safeword.

5 Likes

not sure if it’s intentional… maybe should be called hotword?

1 Like

This looks pretty interesting. Matlab has something like this, which is quite convenient, but applies the fix automatically, without the need for a magic word.

Would it be possible to configure it to happen automatically? Print the error, print “Did you mean…”, and then apply the fix with colored prompt?

2 Likes

That might actually require redefining some Base or REPL methods, so a bit more intrusive.

for REPL use it’s fine, for example OhMyREPL overrides Ctrl-r behavior. SafeREPL replaces all number literals with Big etc.

you can show the “Did you mean …” suggestion and then rethrow the full back trace so users are not missing anything. Making it optional / opt out would be fine too. (just some ideas)

I’ll second the request for a “Did you mean…” approach. The nice thing about that is you can see what you’re going to run before you run it. For example

julia> a = exponential(1)
ERROR: UndefVarError: exponential not defined
Stacktrace:
 [1] top-level scope at REPL[7]:1

julia> fix
[ Info: Fixing UndefVarError(:exponential) with exponent.
┌ Warning: Exception MethodError(exponent, (1,), 0x0000000000006cfd) not implemented.
└ @ TheFix C:\Users\jdiegelm\.julia\packages\TheFix\PB6m1\src\TheFix.jl:198
┌ Warning: Exception MethodError(exponent, (1,), 0x0000000000006cfd) not implemented.
└ @ TheFix C:\Users\jdiegelm\.julia\packages\TheFix\PB6m1\src\TheFix.jl:198

julia> a = exponent(1)
ERROR: MethodError: no method matching exponent(::Int64)
Closest candidates are:
  exponent(::BigFloat) at mpfr.jl:835
  exponent(::Missing) at math.jl:1197
  exponent(::T) where T<:Union{Float16, Float32, Float64} at math.jl:782
Stacktrace:
 [1] top-level scope at none:1
 [2] eval at .\boot.jl:331 [inlined]

What I really wanted here was for it to replace exponential with exp, but exponent was the shorter edit distance, so it did that instead. It would be nice to have a way to decide against an incorrect fix before it happens. As @jling pointed out, there is quite a bit of precedence for packages that modify the behavior of the REPL, so I don’t think many people would find this to be too intrusive.

1 Like

That’s an easy fix! Version v0.2.0 (scheduled to be merged) changes the macro to let the user indicate with a Boolean whether or not their safe word requests confirmation (true) or not (false). The readme has updated examples.

1 Like

Wow! I didn’t catch that! Does it automatically run the suggested fix when you type fix? I’m definitely not a fan of that, it seems incredibly dangerous.

I thought it colored the prompt and printed a suggested fix, and then you had to hit enter.

This is awesome! would be super useful for RFC: JuliaTutor.jl