OS: Ubuntu 16.04
Elm: 0.19
Ellie: https://ellie-app.com/37CtcdKSPrJa1
Using Attribute inside a Msg type and compiling with the --debug flag fails with this error:
elm: Map.!: given key is not an element in the map
CallStack (from HasCallStack):
error, called at ./Data/Map/Internal.hs:610:17 in containers-0.5.11.0-K2TDqgYtGUcKxAY1UqVZ3R:Data.Map.Internal
module Main exposing (main)
import Browser
import Html exposing (Attribute)
type Msg
= Msg (Attribute ())
main : Program () () Msg
main =
Browser.sandbox
{ init = ()
, view = always (Html.div [] [])
, update = \_ model -> model
}
elm make src/Main.elm → OKelm make src/Main.elm --debug → map errorMsg in src/Main.elm to be type Msg = Msg ()elm make src/Main.elm --debug → OKBefore I look into this, what was the goal of putting an Attribute in a Msg?
Some config with attributes in is being passed around. It's probably not a good idea and should be refactored.
same issue happens if using Array type, SSCCE:
module Main exposing (main)
import Browser
import Array exposing (Array)
import Html
type Msg
= Msg (Array ())
main : Program () () Msg
main =
Browser.sandbox
{ init = ()
, view = always (Html.div [] [])
, update = \_ model -> model
}
I encountered a similar issue when using slashmili/phoenix-socket, as soon a I added
PhoenixMsg (PhxMsg.Msg Msg) to my Msg.
module Main exposing (main)
import Browser
import Html exposing (Html, div)
import Phoenix
import Phoenix.Message as PhxMsg
import Phoenix.Socket as Socket
type alias Model =
{ phxSocket : Socket.Socket Msg }
initialSocket =
"ws://localhost:4000/socket/websocket"
|> Socket.init
|> Socket.withLongPoll
init : () -> ( Model, Cmd Msg )
init _ =
( { phxSocket = initialSocket }, Cmd.none )
type Msg
= PhoenixMsg (PhxMsg.Msg Msg)
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
PhoenixMsg innerMsg ->
let
( updatedSocketModel, newCommand ) =
Phoenix.update PhoenixMsg innerMsg model.phxSocket
in
( { model | phxSocket = updatedSocketModel }, newCommand )
main : Program () Model Msg
main =
Browser.element
{ init = init
, view = always (Html.div [] [])
, update = update
, subscriptions = always Sub.none
}
The error also only happens, when used with the --debug flag:
elm: Map.!: given key is not an element in the map
CallStack (from HasCallStack):
error, called at libraries/containers/Data/Map/Internal.hs:603:17 in containers-0.5.10.2:Data.Map.Internal
Same behaviour here but when using RemoteData, removing --debug from elm make solve the issue ...
I did some debugging using the original SSCE code as an example. The full stack trace is
CallStack (from -prof):
Elm.Compiler.Type.Extract.extractUnion.unions (compiler/src/Elm/Compiler/Type/Extract.hs:(138,9)-(140,33))
Elm.Compiler.Type.Extract.extractUnion (compiler/src/Elm/Compiler/Type/Extract.hs:(132,1)-(144,59))
Elm.Compiler.Type.Extract.extractTransitive.(...) (compiler/src/Elm/Compiler/Type/Extract.hs:(107,9)-(111,72))
Elm.Compiler.Type.Extract.extractTransitive (compiler/src/Elm/Compiler/Type/Extract.hs:(97,1)-(119,38))
Elm.Compiler.Type.Extract.fromMsg.(...) (compiler/src/Elm/Compiler/Type/Extract.hs:(90,5)-(91,49))
Elm.Compiler.Type.Extract.fromMsg (compiler/src/Elm/Compiler/Type/Extract.hs:(85,1)-(93,40))
Generate.JavaScript.Expression.toDebugMetadata (compiler/src/Generate/JavaScript/Expression.hs:(1058,1)-(1070,9))
Generate.JavaScript.Expression.generateMain (compiler/src/Generate/JavaScript/Expression.hs:(1038,1)-(1049,38))
Generate.JavaScript.generateExports.starter (compiler/src/Generate/JavaScript.hs:(502,5)-(510,16))
Generate.JavaScript.generateExports (compiler/src/Generate/JavaScript.hs:(500,1)-(520,58))
Which is this line.
Adding some tracing at that point I got:
Couldn't find Canonical {_package = Name {_author = "elm", _project = "virtual-dom"}, _module = Name {_name = "VirtualDom"}} in interfaces`
I logged Map.keySet of the interfaces Map and noticed that not just virtual-dom, but all my other transitive dependencies are missing, and in fact, promoting virtual-dom to a direct dependency makes the issue go away. Html.Attribute is an alias for a virtual-dom type so perhaps that has something to do with it? This is similar to #1802, where moving elm/http to the direct dependencies solved the issue for someone.
Working my way back through the code in the stack trace, I notice that the interfaces map created at this line only uses the direct deps (contained in _app_deps_direct).
I changed this line to:
getExposed deps (Map.union (_app_deps_direct info) (_app_deps_trans info))
and confirmed that the file also compiles with this change. I've no idea if that messes up other stuff though, but with my limited knowledge of what's going on overall.
If I switch to the Array version of the SSCCE (given above), the missing trace output is:
Couldn't find Canonical {_package = Name {_author = "elm", _project = "core"}, _module = Name {_name = "Elm.JsArray"}} in interfaces
and there's no obvious fix like moving a dependency to direct. Array seems to be defined internally in terms of Elm.JsArray but it's not an exposed type.
Hope this is useful in getting a bit closer to a solution.
In my own app, compiling with debug enabled, I get a similar error in the extractAlias function. In this case, the missing module is Canonical {_package = Name {_author = "sporto", _project = "elm-select"}, _module = Name {_name = "Select.Models"}}. Again, this is a hidden module and only the Select module is in the interfaces map.
One more data point.. I was getting this compiler error and it turned out to be the elm-menu library. I think this line of code is the culprit.
https://github.com/ContaSystemer/elm-menu/blob/1.0.0/src/Menu.elm#L139
Getting this error without the debug flag enabled.
@nullbio I've had the error when upgrading a dependency and was able resolve it by deleting elm-stuff - give that a try.
@nullbio I've had the error when upgrading a dependency and was able resolve it by deleting
elm-stuff- give that a try.
Thank you very much, that seems to have fixed it for me.
Same problem here. Using a non-basic type in the Msg crashes the compiler with --debug.
Moved to meta issue in https://github.com/elm/compiler/issues/1851 so I can track everything easier. Thank you @MethodGrab for the report and nice SSCCE!
Everyone else, please open issues with an SSCCE of your case. Adding on to an existing issues with examples that are maybe the same root problem (maybe not!) makes the thread really hard to work with. Just open a fresh issue describing your case on its own.
Most helpful comment
I did some debugging using the original SSCE code as an example. The full stack trace is
Which is this line.
Adding some tracing at that point I got:
I logged
Map.keySetof theinterfacesMap and noticed that not just virtual-dom, but all my other transitive dependencies are missing, and in fact, promotingvirtual-domto a direct dependency makes the issue go away.Html.Attributeis an alias for avirtual-domtype so perhaps that has something to do with it? This is similar to #1802, where movingelm/httpto thedirectdependencies solved the issue for someone.Working my way back through the code in the stack trace, I notice that the
interfacesmap created at this line only uses the direct deps (contained in_app_deps_direct).I changed this line to:
and confirmed that the file also compiles with this change. I've no idea if that messes up other stuff though, but with my limited knowledge of what's going on overall.
If I switch to the
Arrayversion of the SSCCE (given above), the missing trace output is:and there's no obvious fix like moving a dependency to
direct.Arrayseems to be defined internally in terms ofElm.JsArraybut it's not an exposed type.Hope this is useful in getting a bit closer to a solution.