Skip to content

Non fatal error "Data.HashMap.Base.(!): key not found" #181

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
jneira opened this issue Jun 29, 2020 · 7 comments · Fixed by haskell/ghcide#758
Closed

Non fatal error "Data.HashMap.Base.(!): key not found" #181

jneira opened this issue Jun 29, 2020 · 7 comments · Fixed by haskell/ghcide#758
Labels
type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@jneira
Copy link
Member

jneira commented Jun 29, 2020

  • From Bump ghcide to wz1000/hls-2 latest #178
  • The error doesn't break hls usage, you still got diagnostics, hover, etc
  • The error is shown repeteadly when starting the hls server, it seems it is launched at least every time you load a file from a component not already loaded
  • As noted by @1Computer1 it is reproduced at least since 26892d6
@jneira jneira added the type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. label Jun 29, 2020
@ConnorBaker
Copy link

I was browsing the output of the extension (for another issue) and saw that I can reliably trigger this by saving the document I have open. I managed to recreate this with a clean install of VS Code and the latest version of the extension with default settings (so it downloaded and used the latest HLS binaries).

Specifically, creating a project with

stack new mwe simple --resolver lts 

and opening src/main.hs and saving the file five times yields this log:

[client] run command: "/Users/connorbaker/Library/Application Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.2.2-darwin-8.8.3 --lsp"
[client] debug command: "/Users/connorbaker/Library/Application Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.2.2-darwin-8.8.3 --lsp"
[client] server cwd: undefined
haskell-language-server version: 0.2.2.0 (GHC: 8.8.3) (PATH: /Users/connorbaker/Library/Application Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.2.2-darwin-8.8.3) (GIT hash: e44f618c11b7978264a94beeee00d1f014867f6d)
Starting (haskell-language-server)LSP server...
  with arguments: LspArguments {argLSP = True, argsCwd = Nothing, argFiles = [], argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsDebugOn = False, argsLogFile = Nothing, argsThreads = 0, argsProjectGhcVersion = False}
  with plugins: [PluginId "eval",PluginId "floskell",PluginId "ghcide",PluginId "ormolu",PluginId "pragmas",PluginId "stylish-haskell"]
  in directory: /Users/connorbaker/Downloads/mwe
If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option!
 Started LSP server in 0.00s
Data.HashMap.Base.(!): key not found
CallStack (from HasCallStack):
  error, called at ./Data/HashMap/Base.hs:733:16 in nrdrd-cntnrs-0.2.11.0-ba87ae8b:Data.HashMap.Base
  !, called at src/Development/IDE/Import/DependencyInformation.hs:107:40 in ghcide-0.2.0-inplace:Development.IDE.Import.DependencyInformation
2020-08-03 16:11:06.749682 [ThreadId 21] - Opened text document: file:///Users/connorbaker/Downloads/mwe/src/Main.hs
2020-08-03 16:11:06.751645 [ThreadId 63] - Consulting the cradle for "/Users/connorbaker/Downloads/mwe/src/Main.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/Users/connorbaker/Downloads/mwe", cradleOptsProg = CradleAction: Stack}
> Using main module: 1. Package `mwe' component mwe:exe:mwe with main-is file: /Users/connorbaker/Downloads/mwe/src/Main.hs
> Building all executables for `mwe' once. After a successful build of all of them, only specified executables will be rebuilt.
> mwe> configure (exe)
> Configuring mwe-0.1.0.0...
> mwe> initial-build-steps (exe)
> Configuring GHCi with the following packages: mwe
> /Users/connorbaker/Downloads/mwe/.stack-work/install/x86_64-osx/f3d7483496dd8bd90f069c026d66fa8f7f184c590d840d181d13ec2d62e0b560/8.8.3/pkgdb:/Users/connorbaker/.stack/snapshots/x86_64-osx/f3d7483496dd8bd90f069c026d66fa8f7f184c590d840d181d13ec2d62e0b560/8.8.3/pkgdb:/Users/connorbaker/.stack/programs/x86_64-osx/ghc-8.8.3/lib/ghc-8.8.3/package.conf.d
2020-08-03 16:11:10.172521 [ThreadId 63] - Using interface files cache dir: /Users/connorbaker/.cache/ghcide/main-d8d05e9ca6b2f9e9fbfedc994b318ed9989f8938
2020-08-03 16:11:10.172671 [ThreadId 63] - Making new HscEnv[main]
2020-08-03 16:11:10.181051 [ThreadId 135] - finish: CodeAction (took 0.00s)
2020-08-03 16:11:10.456188 [ThreadId 193] - finish: CodeAction:PackageExports (took 0.27s)
2020-08-03 16:11:10.456357 [ThreadId 196] - Plugin.makeCodeLens (ideLogger)
2020-08-03 16:11:10.456613 [ThreadId 193] - finish: codeLens (took 0.00s)
2020-08-03 16:11:10.456777 [ThreadId 202] - GhcIde.hover entered (ideLogger)
2020-08-03 16:11:10.45687 [ThreadId 202] - Hover request at position 5:6 in file: /Users/connorbaker/Downloads/mwe/src/Main.hs
2020-08-03 16:11:39.344504 [ThreadId 21] - Saved text document: file:///Users/connorbaker/Downloads/mwe/src/Main.hs
Data.HashMap.Base.(!): key not found
CallStack (from HasCallStack):
  error, called at ./Data/HashMap/Base.hs:733:16 in nrdrd-cntnrs-0.2.11.0-ba87ae8b:Data.HashMap.Base
  !, called at src/Development/IDE/Import/DependencyInformation.hs:107:40 in ghcide-0.2.0-inplace:Development.IDE.Import.DependencyInformation
2020-08-03 16:11:41.078278 [ThreadId 21] - Saved text document: file:///Users/connorbaker/Downloads/mwe/src/Main.hs
Data.HashMap.Base.(!): key not found
CallStack (from HasCallStack):
  error, called at ./Data/HashMap/Base.hs:733:16 in nrdrd-cntnrs-0.2.11.0-ba87ae8b:Data.HashMap.Base
  !, called at src/Development/IDE/Import/DependencyInformation.hs:107:40 in ghcide-0.2.0-inplace:Development.IDE.Import.DependencyInformation
2020-08-03 16:11:45.365546 [ThreadId 21] - Saved text document: file:///Users/connorbaker/Downloads/mwe/src/Main.hs
Data.HashMap.Base.(!): key not found
CallStack (from HasCallStack):
  error, called at ./Data/HashMap/Base.hs:733:16 in nrdrd-cntnrs-0.2.11.0-ba87ae8b:Data.HashMap.Base
  !, called at src/Development/IDE/Import/DependencyInformation.hs:107:40 in ghcide-0.2.0-inplace:Development.IDE.Import.DependencyInformation
2020-08-03 16:11:46.218652 [ThreadId 21] - Saved text document: file:///Users/connorbaker/Downloads/mwe/src/Main.hs
Data.HashMap.Base.(!): key not found
CallStack (from HasCallStack):
  error, called at ./Data/HashMap/Base.hs:733:16 in nrdrd-cntnrs-0.2.11.0-ba87ae8b:Data.HashMap.Base
  !, called at src/Development/IDE/Import/DependencyInformation.hs:107:40 in ghcide-0.2.0-inplace:Development.IDE.Import.DependencyInformation
2020-08-03 16:11:46.465234 [ThreadId 21] - Saved text document: file:///Users/connorbaker/Downloads/mwe/src/Main.hs
Data.HashMap.Base.(!): key not found
CallStack (from HasCallStack):
  error, called at ./Data/HashMap/Base.hs:733:16 in nrdrd-cntnrs-0.2.11.0-ba87ae8b:Data.HashMap.Base
  !, called at src/Development/IDE/Import/DependencyInformation.hs:107:40 in ghcide-0.2.0-inplace:Development.IDE.Import.DependencyInformation

It looks like the first one is caused by opening file, and I saw each of the ones at the end happen as soon as I saved the file (this was without making any changes to the file, though I saw the same error logged if I made changes to the file and saved it).

Does this match what you've seen?

@jneira
Copy link
Member Author

jneira commented Aug 3, 2020

Yeah, i had not recognize the pattern but it matches your observations

@sir4ur0n
Copy link
Collaborator

I was starting to play around with HLS today and decided to take a look at this issue because it annoys me a lot whenever I startup HLS to see this 😄

The problem happens even on a brand new Stack project (stack new foobar) at HLS start on the project, so it's easy to reproduce.

Though I can't tell (yet?) the root cause, I have found some interesting things, by comparing with running Ghcide directly on the same project (which doesn't throw).

As showed by the exception, the problem happens in Development.IDE.Import.DependencyInformation.pathToId which is called by reverseDependencies (in the same module) with a basically empty DependencyInformation (all fields are empty: DependencyInformation {depErrorNodes = fromList [], depModuleNames = fromList [], depModuleDeps = fromList [], depReverseModuleDeps = fromList [], depPkgDeps = fromList [], depPathIdMap = PathIdMap {idToPathMap = fromList [], pathToIdMap = fromList []}, depBootMap = fromList []}).

This "empty" DependencyInformation in turn comes from Development.IDE.Core.FileStore.typecheckParentsAction coming from useNoFile_ GetModuleGraph.

As I have no effing clue what this is or what this is supposed to return, I can hardly go further in this investigation 😄 But notice that Ghcide does not go through this function when started directly 🤷‍♂️

Hope this newbie investigation can help someone more knowledgeable understand what's going on!

@lukel97
Copy link
Collaborator

lukel97 commented Aug 18, 2020

cc @wz1000

@wz1000
Copy link
Collaborator

wz1000 commented Aug 18, 2020

This is harmless, I would suggest you ignore it for now.

It happens because we cannot initially construct a complete module graph since we don't know about all the files in the project. This is soon resolved, so it disappears.

@codygman
Copy link

codygman commented Sep 1, 2020

I got this while trying to evaluate some code inline like:

data Person = Person { name :: String, age :: Int} deriving Show -- deriving (Show, Generic)
-- >>> Person "codygman" 0

I did evaluate the part with deriving generic first so not sure if that's related here. All I know is the only error that came up:

2020-09-01 15:48:52.28711788 [ThreadId 66] - Data.HashMap.Internal.(!): key not found
CallStack (from HasCallStack):
  error, called at ./Data/HashMap/Internal.hs:753:16 in unordered-containers-0.2.12.0-2e3fe165d2481c3a755449eca3083a286519fe98ac20523b8f479e0645004f51:Data.HashMap.Internal
  !, called at src/Development/IDE/Import/DependencyInformation.hs:107:40 in ghcide-0.2.0-inplace:Development.IDE.Import.DependencyInformation

Actually something else to note that is every time I click "Evaluate" it always tries to rebuild, so I think this could be a case where not having that module information is a cause.

@buggymcbugfix
Copy link
Contributor

buggymcbugfix commented Sep 4, 2020

I'm getting a similar error trying to evaluate my code example from here:

module Main where

data Boolean = O | I

-- >>> not O
not :: Boolean -> Boolean
not O = I
not I = I
2020-09-04 08:15:21.412305 [ThreadId 21] - Opened text document: file:///Users/vl200/temp/test.hs
2020-09-04 08:15:21.414263 [ThreadId 62] - Data.HashMap.Internal.(!): key not found
CallStack (from HasCallStack):
  error, called at ./Data/HashMap/Internal.hs:753:16 in nrdrd-cntnrs-0.2.12.0-909b901a:Data.HashMap.Internal
  !, called at src/Development/IDE/Import/DependencyInformation.hs:107:40 in ghcide-0.2.0-inplace:Development.IDE.Import.DependencyInformation
2020-09-04 08:15:21.415169 [ThreadId 65] - Consulting the cradle for "/Users/vl200/temp/test.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/Users/vl200/temp", cradleOptsProg = CradleAction: Default}
2020-09-04 08:15:21.646975 [ThreadId 65] - Using interface files cache dir: /Users/vl200/.cache/ghcide/main-da39a3ee5e6b4b0d3255bfef95601890afd80709
2020-09-04 08:15:21.647138 [ThreadId 65] - Making new HscEnv[main]

(VSCode on mac)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants