# \[ANN\] TheFix.jl for the REPL

**URL:** <https://discourse.julialang.org/t/ann-thefix-jl-for-the-repl/48304>\
**Category:** Package Announcements\
**Created:** [October 13, 2020, 2:52pm UTC](https://discourse.julialang.org/t/ann-thefix-jl-for-the-repl/48304 "2020-10-13T14:52:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikaelSlevinsky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikaelslevinsky/32/38545_2.png) [@MikaelSlevinsky](https://discourse.julialang.org/u/MikaelSlevinsky)\
**Post date:** [October 13, 2020, 2:52pm UTC](https://discourse.julialang.org/t/ann-thefix-jl-for-the-repl/48304/1 "2020-10-13T14:52:36Z")

</div>

I’m happy to announce [TheFix.jl](https://github.com/MikaelSlevinsky/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:

 ![TheFix](https://global.discourse-cdn.com/julialang/original/3X/b/c/bc81211587197866c0d0157e4b188efa81f7e3a2.gif)

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.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 13, 2020, 2:53pm UTC](https://discourse.julialang.org/t/ann-thefix-jl-for-the-repl/48304/2 "2020-10-13T14:53:51Z")

</div>

remind me of [https://github.com/nvbn/thefuck](https://github.com/nvbn/thefuck)

---

<div class="post-metadata">

**Author:** ![MikaelSlevinsky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikaelslevinsky/32/38545_2.png) [@MikaelSlevinsky](https://discourse.julialang.org/u/MikaelSlevinsky)\
**Post date:** [October 13, 2020, 2:54pm UTC](https://discourse.julialang.org/t/ann-thefix-jl-for-the-repl/48304/3 "2020-10-13T14:54:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 13, 2020, 2:56pm UTC](https://discourse.julialang.org/t/ann-thefix-jl-for-the-repl/48304/4 "2020-10-13T14:56:25Z")

</div>

> [@MikaelSlevinsky](#):
>
> safeword

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

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [October 13, 2020, 2:58pm UTC](https://discourse.julialang.org/t/ann-thefix-jl-for-the-repl/48304/5 "2020-10-13T14:58:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![MikaelSlevinsky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikaelslevinsky/32/38545_2.png) [@MikaelSlevinsky](https://discourse.julialang.org/u/MikaelSlevinsky)\
**Post date:** [October 13, 2020, 3:04pm UTC](https://discourse.julialang.org/t/ann-thefix-jl-for-the-repl/48304/6 "2020-10-13T15:04:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 14, 2020, 9:31pm UTC](https://discourse.julialang.org/t/ann-thefix-jl-for-the-repl/48304/7 "2020-10-14T21:31:34Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![jonniedie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonniedie/32/12842_2.png) [@jonniedie](https://discourse.julialang.org/u/jonniedie)\
**Post date:** [October 15, 2020, 3:23pm UTC](https://discourse.julialang.org/t/ann-thefix-jl-for-the-repl/48304/8 "2020-10-15T15:23:26Z")

</div>

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
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.

---

<div class="post-metadata">

**Author:** ![MikaelSlevinsky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikaelslevinsky/32/38545_2.png) [@MikaelSlevinsky](https://discourse.julialang.org/u/MikaelSlevinsky)\
**Post date:** [October 15, 2020, 5:28pm UTC](https://discourse.julialang.org/t/ann-thefix-jl-for-the-repl/48304/9 "2020-10-15T17:28:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [October 15, 2020, 6:27pm UTC](https://discourse.julialang.org/t/ann-thefix-jl-for-the-repl/48304/10 "2020-10-15T18:27:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [October 15, 2020, 9:30pm UTC](https://discourse.julialang.org/t/ann-thefix-jl-for-the-repl/48304/11 "2020-10-15T21:30:58Z")

</div>

This is awesome! would be super useful for [RFC: JuliaTutor.jl](https://discourse.julialang.org/t/rfc-juliatutor-jl/43335)
