# Why are kwargs printed in full in a MethodError?

**URL:** <https://discourse.julialang.org/t/why-are-kwargs-printed-in-full-in-a-methoderror/80592>\
**Category:** Internals & Design\
**Tags:** error\
**Created:** [May 6, 2022, 6:53am UTC](https://discourse.julialang.org/t/why-are-kwargs-printed-in-full-in-a-methoderror/80592 "2022-05-06T06:53:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [May 6, 2022, 6:53am UTC](https://discourse.julialang.org/t/why-are-kwargs-printed-in-full-in-a-methoderror/80592/1 "2022-05-06T06:53:32Z")

</div>

```julia
julia> f(a::Int; b = nothing) = a
f (generic function with 1 method)

julia> f(2.0, b = zeros(10))
ERROR: MethodError: no method matching f(::Float64; b=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
Closest candidates are:
  f(::Int64; b) at REPL[1]:1
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

```

In this case, the error is not due to the value/type of `b`, and displaying unnecessary information may actually make it harder to locate the actual error. Maybe the value of `b` should only be printed if the error is due to a type-mismatch on it? In this case, however, a `TypeError` is raised, and the value isn’t displayed at all.

```julia
julia> h(a::Int; b::Float64 = 0.0) = a
h (generic function with 1 method)

julia> h(2, b = 4)
ERROR: TypeError: in keyword argument b, expected Float64, got a value of type Int64
Stacktrace:
 [1] top-level scope
   @ REPL[9]:1

```

So… maybe we don’t need to display the values of kwargs at all?

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [May 6, 2022, 7:01am UTC](https://discourse.julialang.org/t/why-are-kwargs-printed-in-full-in-a-methoderror/80592/2 "2022-05-06T07:01:29Z")

</div>

I often find it helpful to see values in error messages. Deep in a call stack I’d have to invoke a debugger to see what’s going on. It can make it harder to read, too, as you say. It would be nice to have a way of expanding/hiding information in an error.

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [May 6, 2022, 7:07am UTC](https://discourse.julialang.org/t/why-are-kwargs-printed-in-full-in-a-methoderror/80592/3 "2022-05-06T07:07:04Z")

</div>

Unfortunately, with nested tuples of custom types that define their own multi-line `show` methods, displaying them can quickly get messy. In my real use case, I had a terminal full of 150+ lines of a keyword argument being displayed, that had nothing to do with the error that I had to resolve.

---

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [May 6, 2022, 7:55am UTC](https://discourse.julialang.org/t/why-are-kwargs-printed-in-full-in-a-methoderror/80592/4 "2022-05-06T07:55:11Z")

</div>

I also don’t understand the need to print the kwargs in full. It is done quite intentionally though if you look at the source.

Might be worth opening an issue for? At least to limit the output on tuple types etc.

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [May 10, 2022, 5:11am UTC](https://discourse.julialang.org/t/why-are-kwargs-printed-in-full-in-a-methoderror/80592/5 "2022-05-10T05:11:38Z")

</div>

I’ve opened [an issue](https://github.com/JuliaLang/julia/issues/45219) about this
