# Strange error after an error occurred with \`isvalid(::AbstractString, ::Integer)\`

**URL:** <https://discourse.julialang.org/t/strange-error-after-an-error-occurred-with-isvalid-abstractstring-integer/8234>\
**Category:** Internals & Design\
**Created:** [January 8, 2018, 2:58pm UTC](https://discourse.julialang.org/t/strange-error-after-an-error-occurred-with-isvalid-abstractstring-integer/8234 "2018-01-08T14:58:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [January 8, 2018, 2:58pm UTC](https://discourse.julialang.org/t/strange-error-after-an-error-occurred-with-isvalid-abstractstring-integer/8234/1 "2018-01-08T14:58:06Z")

</div>

I got the following:

```julia
  Got an exception of type MethodError outside of a @test
┌ Error: Error showing method candidates, aborted
│ exception =
│ MethodError: no method matching length(::Type{Tuple{UTF16Str,Int64}})
│ Closest candidates are:
│ length(::SimpleVector) at essentials.jl:544
│ length(::Base.MethodList) at reflection.jl:671
│ length(::MethodTable) at reflection.jl:746
│ ...
│ Stacktrace:
│ [1] show_method_candidates(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::MethodError, ::Any) at ./replutil.jl:551
│

```

This is the code that got called, which had gotten a method error:

```julia
@propagate_inbounds isvalid(s::AbstractString, i::Integer) = typeof(i) === Int ?
    throw(MethodError(isvalid, Tuple{typeof(s),Int})) : isvalid(s, Int(i))

```

and the error that caused the failure was this:

```julia
  MethodError: no method matching isvalid(::UTF16Str, ::Int64)
  Stacktrace:
   [1] isvalid at ./strings/basic.jl:121 [inlined]
   [2] SubString{UTF16Str}(::UTF16Str, ::Int64, ::Int64) at ./strings/substring.jl:31

```

This was all on master, v"0.7.0-DEV.3323"

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [January 8, 2018, 3:08pm UTC](https://discourse.julialang.org/t/strange-error-after-an-error-occurred-with-isvalid-abstractstring-integer/8234/2 "2018-01-08T15:08:37Z")

</div>

Looks like the code throwing the error has a typo, and should be:

```julia
throw(MethodError(isvalid, (s, i)))

```

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [January 8, 2018, 3:15pm UTC](https://discourse.julialang.org/t/strange-error-after-an-error-occurred-with-isvalid-abstractstring-integer/8234/3 "2018-01-08T15:15:01Z")

</div>

There are a number of places there that all have `Tuple{typeof(s),Int}`, so I suppose they all would need to get fixed. Is this just some really old syntax from before my time that wasn’t updated, or these methods don’t have unit tests that check that the error case works?

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [January 9, 2018, 9:52pm UTC](https://discourse.julialang.org/t/strange-error-after-an-error-occurred-with-isvalid-abstractstring-integer/8234/4 "2018-01-09T21:52:35Z")

</div>

AFAICT there are three occurrences which are all in the same file, so I’d say it’s just an oversight. @StefanKarpinski must know.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 9, 2018, 10:26pm UTC](https://discourse.julialang.org/t/strange-error-after-an-error-occurred-with-isvalid-abstractstring-integer/8234/5 "2018-01-09T22:26:28Z")

</div>

Please open an issue and I’ll take a look.
