Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[VSCode] Error "command /usr/bin/mix credo returns empty output" #8

Closed
lqmanh opened this issue Mar 4, 2021 · 38 comments
Closed

[VSCode] Error "command /usr/bin/mix credo returns empty output" #8

lqmanh opened this issue Mar 4, 2021 · 38 comments

Comments

@lqmanh
Copy link

lqmanh commented Mar 4, 2021

Hi,
I've been trying to install this extension but encountered the error above. Here's full version:

command `/usr/bin/mix credo` returns empty output! please check configuration.
        Did you add or modify your dependencies? You might need to run `mix deps.get` or recompile.

That's weird because I already have credo installed and I can run mix credo manually in terminal without problem.

Could you please have a look at this? Thank you for your great work.

@pantajoe
Copy link
Owner

pantajoe commented Mar 4, 2021

Hi! Thanks for submitting this issue. That seems very strange to me. Have you encountered this when opening a certain file or simply always when opening a workspace?
And could you run the following command in your terminal and send me the output?

/usr/bin/mix credo --format json --read-from-stdin --config-file .credo.exs --config-name default < "<content of any .ex/.exs file>"

Normally, this error occurs if mix is run in a directory where not all dependencies are installed or where no mix.exs file exists. Maybe you have your mix.exs file in a subdirectory or something?

@lqmanh
Copy link
Author

lqmanh commented Mar 4, 2021

@pantajoe
It seems like the extension couldn't correctly identify the project root. When I removed all other projects from the workspace, it works fine now. It also works when my Elixir app is the 1st entry in the workspace.

@pantajoe
Copy link
Owner

pantajoe commented Mar 5, 2021

Okay, thanks for the update. I'll look into that to support multi-workspace scenarios.

@PJUllrich
Copy link

PJUllrich commented Mar 12, 2021

Hey there, I received the same error upon starting VSCode, however I only had a single project in the workspace.
It turned out that my globally installed credo was missing the jason dependency. Here's how I found out:

I ran your command from above.

> /Users/pullrich/.asdf/shims/mix credo --format json --read-from-stdin --config-file .credo.exs --config-name default < ./lib/rollbar.ex

** (UndefinedFunctionError) function Jason.encode!/2 is undefined (module Jason is not available)
    Jason.encode!(%{"issues" => []}, [pretty: true])
    lib/credo/cli/output/formatter/json.ex:15: Credo.CLI.Output.Formatter.JSON.print_map/1
    lib/credo/cli/command/suggest/suggest_command.ex:67: Credo.CLI.Command.Suggest.SuggestCommand.PrintResultsAndSummary.call/2
    lib/credo/execution/task.ex:55: Credo.Execution.Task.do_run/3
    (elixir 1.11.2) lib/enum.ex:2181: Enum."-reduce/3-lists^foldl/2-0-"/3
    lib/credo/execution/task.ex:55: Credo.Execution.Task.do_run/3
    (elixir 1.11.2) lib/enum.ex:2181: Enum."-reduce/3-lists^foldl/2-0-"/3
    lib/credo.ex:30: Credo.run/1

So, I installed jason globally as well with mix archive.install hex jason and ran the command again:

> /Users/pullrich/.asdf/shims/mix credo --format json --read-from-stdin --config-file .credo.exs --config-name default < ./lib/rollbar.ex

{
  "issues": []
}

So, the problem was not that credo returned an empty output, but that it threw an exception which the VSCode extension didn't pick up. I'm not sure how easy it is to listen for exceptions, but if possible, I'd suggest the extension shows a different error-message in case an exception occurs.

But aside from this litte FYI: Thank you very much for this very helpful extension :)

@pantajoe
Copy link
Owner

@PJUllrich Thanks for pointing this out! Currently, I am capturing exceptions if credo's command returns an non-zero exit status. Just to clarify, the command that returns the elixir exception does not return a success status and, thus, no JSON output, does it?

@PJUllrich
Copy link

That is correct I believe. No JSON output is returned, only what you see above. I believe that that's not considered a "successful return status" indeed.

@pantajoe
Copy link
Owner

@lqmanh Hey, I just released a new version that now supports having multiple folders in one workspace. So if you have 2 or more folders opened, and only one elixir project, no more errors should occur, even if the elixir project is not the first folder in the list.

@lqmanh
Copy link
Author

lqmanh commented Apr 11, 2021

@pantajoe Thank you!

@hfjallemark
Copy link

I'm still getting this error in 0.4.1:

Here's from the output:

> Retreiving credo information: Executing credo command `/Users/Hans/.asdf/shims/mix credo info --format json --verbose` for '/Users/Hans/Dev/app/lib/my_app/my_module.ex'

> Removing linter messages and cancel running linting processes for '/Users/Hans/Dev/app/lib/my_app/my_module.ex'.

> Command `/Users/Hans/.asdf/shims/mix credo` returns empty output! please check configuration. Did you add or modify your dependencies? You might need to run `mix deps.get` or recompile.

I've run both mix deps.get and recompiled the app.

@pantajoe
Copy link
Owner

Have you run mix credo in your project directory and what is the output, @hfjallemark ?

@hfjallemark
Copy link

Yes here's the output:

$ mix credo
Checking 306 source files (this might take a while) ...
...
Analysis took 1.9 seconds (0.2s to load, 1.7s running 53 checks on 306 files)
1245 mods/funs, found 2 warnings, 10 refactoring opportunities, 1 code readability issue.

And running the command above:

$ /Users/Hans/.asdf/shims/mix credo --format json /Users/Hans/Dev/app/lib/my_app/my_module.ex
{
  "issues": []
}

@pantajoe
Copy link
Owner

And the problem still occurs? How do you have your project opened in vscode? As a saved workspace? As a folder?

@hfjallemark
Copy link

Yep still occurs. I've opened my project as a folder.

@pantajoe
Copy link
Owner

Hmm, could you activate the configuration option elixir.credo.lintEverything and try again and get back to me whether it works or not?

@hfjallemark
Copy link

Where? In .credo.exs or VS Code settings?

@pantajoe
Copy link
Owner

In VS Code settings

@pantajoe
Copy link
Owner

@hfjallemark elixir.credo.lintEverything is a configuration option from this VS Code extension.
Normally, in order to respect the credo configuration's options for including and excluding file globs, 2 commands are executed:

  • First, mix credo info --format json --verbose is executed, that returns an array of all files in the project directory that should be linted
  • If the current file is inside this allowlist, the command mix credo --format json --read-from-stdin ... is executed on the file's contents

The configuration option elixir.credo.lintEverything bypasses this. Therefore, the command mix credo info is never executed. And, therefore, the output channel should not including a line like Retreiving credo information: ..., but the credo command directly. I think it would be very helpful if you tell me whether the command /Users/Hans/.asdf/shims/mix credo info --format json --verbose returns sensible JSON output with a property config.files that is an array of relative file paths.

@hfjallemark
Copy link

That seemed to work! Awesome, thanks 👍

@pantajoe
Copy link
Owner

Great! @hfjallemark Could you maybe send me the output of your command /Users/Hans/.asdf/shims/mix credo info --format json --verbose executed in your project directory please? It would be great, so I can maybe pin-point the problem then. 😄

@hfjallemark
Copy link

Sure, here it is:

{
  "config": {
    "checks": [
      "Elixir.Credo.Check.Consistency.ExceptionNames",
      "Elixir.Credo.Check.Consistency.LineEndings",
      "Elixir.Credo.Check.Consistency.ParameterPatternMatching",
      "Elixir.Credo.Check.Consistency.SpaceAroundOperators",
      "Elixir.Credo.Check.Consistency.SpaceInParentheses",
      "Elixir.Credo.Check.Consistency.TabsOrSpaces",
      "Elixir.Credo.Check.Design.AliasUsage",
      "Elixir.Credo.Check.Design.TagTODO",
      "Elixir.Credo.Check.Design.TagFIXME",
      "Elixir.Credo.Check.Readability.AliasOrder",
      "Elixir.Credo.Check.Readability.FunctionNames",
      "Elixir.Credo.Check.Readability.LargeNumbers",
      "Elixir.Credo.Check.Readability.MaxLineLength",
      "Elixir.Credo.Check.Readability.ModuleAttributeNames",
      "Elixir.Credo.Check.Readability.ModuleNames",
      "Elixir.Credo.Check.Readability.ParenthesesInCondition",
      "Elixir.Credo.Check.Readability.ParenthesesOnZeroArityDefs",
      "Elixir.Credo.Check.Readability.PredicateFunctionNames",
      "Elixir.Credo.Check.Readability.PreferImplicitTry",
      "Elixir.Credo.Check.Readability.RedundantBlankLines",
      "Elixir.Credo.Check.Readability.Semicolons",
      "Elixir.Credo.Check.Readability.SpaceAfterCommas",
      "Elixir.Credo.Check.Readability.StringSigils",
      "Elixir.Credo.Check.Readability.TrailingBlankLine",
      "Elixir.Credo.Check.Readability.TrailingWhiteSpace",
      "Elixir.Credo.Check.Readability.UnnecessaryAliasExpansion",
      "Elixir.Credo.Check.Readability.VariableNames",
      "Elixir.Credo.Check.Refactor.CondStatements",
      "Elixir.Credo.Check.Refactor.CyclomaticComplexity",
      "Elixir.Credo.Check.Refactor.FunctionArity",
      "Elixir.Credo.Check.Refactor.LongQuoteBlocks",
      "Elixir.Credo.Check.Refactor.MatchInCondition",
      "Elixir.Credo.Check.Refactor.NegatedConditionsInUnless",
      "Elixir.Credo.Check.Refactor.NegatedConditionsWithElse",
      "Elixir.Credo.Check.Refactor.Nesting",
      "Elixir.Credo.Check.Refactor.UnlessWithElse",
      "Elixir.Credo.Check.Refactor.WithClauses",
      "Elixir.Credo.Check.Warning.ApplicationConfigInModuleAttribute",
      "Elixir.Credo.Check.Warning.BoolOperationOnSameValues",
      "Elixir.Credo.Check.Warning.ExpensiveEmptyEnumCheck",
      "Elixir.Credo.Check.Warning.IExPry",
      "Elixir.Credo.Check.Warning.IoInspect",
      "Elixir.Credo.Check.Warning.OperationOnSameValues",
      "Elixir.Credo.Check.Warning.OperationWithConstantResult",
      "Elixir.Credo.Check.Warning.RaiseInsideRescue",
      "Elixir.Credo.Check.Warning.UnusedEnumOperation",
      "Elixir.Credo.Check.Warning.UnusedFileOperation",
      "Elixir.Credo.Check.Warning.UnusedKeywordOperation",
      "Elixir.Credo.Check.Warning.UnusedListOperation",
      "Elixir.Credo.Check.Warning.UnusedPathOperation",
      "Elixir.Credo.Check.Warning.UnusedRegexOperation",
      "Elixir.Credo.Check.Warning.UnusedStringOperation",
      "Elixir.Credo.Check.Warning.UnusedTupleOperation",
      "Elixir.Credo.Check.Warning.UnsafeExec"
    ],
    "files": [
      "lib/my_app.ex",
      "lib/my_app/application.ex",
      "lib/my_app/repo.ex",
      "lib/my_app_web.ex",
      "lib/my_app_web/endpoint.ex",
      "lib/my_app_web/error_view.ex",
      "lib/my_app_web/hello/controller.ex",
      "lib/my_app_web/hello/templates/index.html.exs",
      "lib/my_app_web/hello/view.ex",
      "lib/my_app_web/home/controller.ex",
      "lib/my_app_web/home/templates/index.html.exs",
      "lib/my_app_web/layout/templates/app.html.exs",
      "lib/my_app_web/layout/view.ex",
      "lib/my_app_web/router.ex",
      "test/support/conn_case.ex",
      "test/support/data_case.ex",
      "test/test_helper.exs",
      "test/my_app_web/controllers/hello_controller_test.exs",
      "test/my_app_web/controllers/home_controller_test.exs",
      "test/my_app_web/features/home_test.exs"
    ]
  },
  "system": {
    "credo": "1.5.4-ref.main.7a25d44+uncommittedchanges",
    "elixir": "1.11.2",
    "erlang": "23"
  }
}

@pantajoe
Copy link
Owner

@hfjallemark Thanks a lot! It does look correct, though.

@pantajoe
Copy link
Owner

@hfjallemark One more question:
I just released a new version with improved error reporting. In order to debug this error you had, I would be very grateful if you could download this new version in vs code, enable the extension's debug mode by setting "elixir.credo.enableDebug" to true, and show me the output of the extension's output channel when you have the configuration option "elixir.credo.lintEverything" disabled.

@hfjallemark
Copy link

Looks like I'm getting a different error now:

> Retreiving credo information: Executing credo command `/Users/Hans/.asdf/shims/mix credo info --format json --verbose` for '/Users/Hans/Dev/app/lib/my_app/my_module.ex' in directory '/Users/Hans/Dev/app'

> Warning: "** (exit) exited in: GenServer.call(Mix.ProjectStack, {:get_stack, #Function<10.84060762/1 in Mix.ProjectStack.peek/0>}, :infinity)
    ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
    (elixir 1.11.2) lib/gen_server.ex:1017: GenServer.call/3
    (mix 1.11.2) lib/mix/project.ex:196: Mix.Project.config/0
    (mix 1.11.2) lib/mix/project.ex:378: Mix.Project.deps_path/0
    (mix 1.11.2) lib/mix/dep/loader.ex:181: Mix.Dep.Loader.with_scm_and_app/4
    (mix 1.11.2) lib/mix/dep/loader.ex:147: Mix.Dep.Loader.to_dep/3
    (elixir 1.11.2) lib/enum.ex:1399: Enum."-map/2-lists^map/1-0-"/2
    (mix 1.11.2) lib/mix/dep/loader.ex:333: Mix.Dep.Loader.mix_dep/2
    (mix 1.11.2) lib/mix/dep/loader.ex:101: Mix.Dep.Loader.load/2
"

> Error on parsing output (It might be non-JSON output): " 07:27:08.987 [info]  SIGTERM received - shutting down  "

@hfjallemark
Copy link

In addition to the error above I'm also getting:

> Command `/Users/Hans/.asdf/shims/mix credo` returns empty output! Please check your configuration. Did you add or modify your dependencies? You might need to run `mix deps.get` or recompile.

@pantajoe
Copy link
Owner

Hm, this is definitely weird. /Users/Hans/.asdf/shims/mix credo info --format json --verbose still does not produce any error when run in the directory /Users/Hans/Dev/app ? Do you maybe have a repo with the project?

@gigitux
Copy link

gigitux commented Jun 20, 2021

First of all thanks for this extension. I have the same error: this is the output of mix credo info --format json --verbose.

Seems that I have the error only on .exs files

{
  "config": {
    "checks": [
      "Elixir.Credo.Check.Consistency.ExceptionNames",
      "Elixir.Credo.Check.Consistency.LineEndings",
      "Elixir.Credo.Check.Consistency.ParameterPatternMatching",
      "Elixir.Credo.Check.Consistency.SpaceAroundOperators",
      "Elixir.Credo.Check.Consistency.SpaceInParentheses",
      "Elixir.Credo.Check.Consistency.TabsOrSpaces",
      "Elixir.Credo.Check.Design.AliasUsage",
      "Elixir.Credo.Check.Design.TagTODO",
      "Elixir.Credo.Check.Design.TagFIXME",
      "Elixir.Credo.Check.Readability.AliasOrder",
      "Elixir.Credo.Check.Readability.FunctionNames",
      "Elixir.Credo.Check.Readability.LargeNumbers",
      "Elixir.Credo.Check.Readability.MaxLineLength",
      "Elixir.Credo.Check.Readability.ModuleAttributeNames",
      "Elixir.Credo.Check.Readability.ModuleDoc",
      "Elixir.Credo.Check.Readability.ModuleNames",
      "Elixir.Credo.Check.Readability.ParenthesesInCondition",
      "Elixir.Credo.Check.Readability.ParenthesesOnZeroArityDefs",
      "Elixir.Credo.Check.Readability.PredicateFunctionNames",
      "Elixir.Credo.Check.Readability.PreferImplicitTry",
      "Elixir.Credo.Check.Readability.RedundantBlankLines",
      "Elixir.Credo.Check.Readability.Semicolons",
      "Elixir.Credo.Check.Readability.SpaceAfterCommas",
      "Elixir.Credo.Check.Readability.StringSigils",
      "Elixir.Credo.Check.Readability.TrailingBlankLine",
      "Elixir.Credo.Check.Readability.TrailingWhiteSpace",
      "Elixir.Credo.Check.Readability.UnnecessaryAliasExpansion",
      "Elixir.Credo.Check.Readability.VariableNames",
      "Elixir.Credo.Check.Refactor.CondStatements",
      "Elixir.Credo.Check.Refactor.CyclomaticComplexity",
      "Elixir.Credo.Check.Refactor.FunctionArity",
      "Elixir.Credo.Check.Refactor.LongQuoteBlocks",
      "Elixir.Credo.Check.Refactor.MatchInCondition",
      "Elixir.Credo.Check.Refactor.NegatedConditionsInUnless",
      "Elixir.Credo.Check.Refactor.NegatedConditionsWithElse",
      "Elixir.Credo.Check.Refactor.Nesting",
      "Elixir.Credo.Check.Refactor.UnlessWithElse",
      "Elixir.Credo.Check.Refactor.WithClauses",
      "Elixir.Credo.Check.Warning.ApplicationConfigInModuleAttribute",
      "Elixir.Credo.Check.Warning.BoolOperationOnSameValues",
      "Elixir.Credo.Check.Warning.ExpensiveEmptyEnumCheck",
      "Elixir.Credo.Check.Warning.IExPry",
      "Elixir.Credo.Check.Warning.IoInspect",
      "Elixir.Credo.Check.Warning.OperationOnSameValues",
      "Elixir.Credo.Check.Warning.OperationWithConstantResult",
      "Elixir.Credo.Check.Warning.RaiseInsideRescue",
      "Elixir.Credo.Check.Warning.UnusedEnumOperation",
      "Elixir.Credo.Check.Warning.UnusedFileOperation",
      "Elixir.Credo.Check.Warning.UnusedKeywordOperation",
      "Elixir.Credo.Check.Warning.UnusedListOperation",
      "Elixir.Credo.Check.Warning.UnusedPathOperation",
      "Elixir.Credo.Check.Warning.UnusedRegexOperation",
      "Elixir.Credo.Check.Warning.UnusedStringOperation",
      "Elixir.Credo.Check.Warning.UnusedTupleOperation",
      "Elixir.Credo.Check.Warning.UnsafeExec"
    ],
    "files": [
      "lib/config/config.ex",
      "lib/hello/hello.handler.ex",
      "lib/quote/quote.schema.ex",
      "lib/quotes_reminder_bot.ex",
      "lib/repo/repo.ex",
      "lib/send_quotes/send_quotes.handler.ex",
      "lib/state/state.ex",
      "lib/state/state.type.ex",
      "lib/user/user.schema.ex",
      "test/quotes_reminder_bot_test.exs",
      "test/test_helper.exs"
    ]
  },
  "system": {
    "credo": "1.5.6",
    "elixir": "1.12.0",
    "erlang": "24"
  }
}

@pantajoe
Copy link
Owner

@gigitux What OS do you use? And what does the output channel show if you have the configuration option "elixir.credo.enableDebug" enabled when the error is thrown?

@pantajoe pantajoe reopened this Jun 22, 2021
@gigitux
Copy link

gigitux commented Jun 22, 2021

@gigitux What OS do you use? And what does the output channel show if you have the configuration option "elixir.credo.enableDebug" enabled when the error is thrown?

OSX 11.4

Warning

Warning: "** (exit) exited in: GenServer.call(Mix.State, {:get, {Map, :get, [:remote_converger, nil]}}, :infinity) ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started (elixir 1.12.0) lib/gen_server.ex:1014: GenServer.call/3 (mix 1.12.0) lib/mix/dep/converger.ex:73: anonymous fn/1 in Mix.Dep.Converger.all/4 (mix 1.12.0) lib/mix/dep/converger.ex:185: Mix.Dep.Converger.all/9 (mix 1.12.0) lib/mix/dep/converger.ex:201: Mix.Dep.Converger.all/9 (mix 1.12.0) lib/mix/dep/converger.ex:123: Mix.Dep.Converger.all/7 (mix 1.12.0) lib/mix/dep/converger.ex:72: Mix.Dep.Converger.all/4 (mix 1.12.0) lib/mix/dep/converger.ex:51: Mix.Dep.Converger.converge/4 (mix 1.12.0) lib/mix/dep.ex:193: Mix.Dep.converge/1 "

Error

Error on parsing output (It might be non-JSON output): " 12:39:53.717 [info] SIGTERM received - shutting down "

@pantajoe
Copy link
Owner

pantajoe commented Jul 4, 2021

@gigitux So weird. And if you set "elixir.credo.lintEverything": true? Do you get the same error?
And regardless what you do and how many times you hit Cmd+Save on an opened Elixir document, does the same error occur?

@lvl3
Copy link
Contributor

lvl3 commented Sep 2, 2021

I got the same error that is mentioned in the title. However I did managed to fix it. I tried to retrace my steps, so I could share them with you guys. Maybe this'll help someone. I'm running Ubuntu 18.04 and VSCodium (VSCode without proprietary parts).

I wanted to run credo as standalone installation instead of adding it to a project. After installing the extension I followed the instructions on https://hexdocs.pm/credo/basic_usage.html with a few minor exceptions with the folder structures. Here are the steps copied from hexdocs .

git clone git@github.com:rrrene/bunt.git
cd bunt
mix archive.build
mix archive.install
cd -
git clone git@github.com:rrrene/credo.git
cd credo
mix deps.get
mix archive.build
mix archive.install

After this:

  1. mix credo gen.config in the project's root folder
  2. Installed Jason with mix archive.install hex jason
  3. Restart VSCodium

I no longer get the error mentioned in the title.

@lvl3
Copy link
Contributor

lvl3 commented Sep 2, 2021

One more thing I noticed. This problem could be related to .credo.exs on project's root dir. I encountered the problem a second time with a different project.

On opening the project with VSCodium I got the error mentioned in the title. Then I tried to generate .credo.exs with mix credo gen.config. The error message stated that I had a syntax error in my config/dev.exs file. That turned out to be a typo. After I fixed it, I managed to create .credo.exs and the problem with the extension went away.

@pantajoe
Copy link
Owner

pantajoe commented Sep 2, 2021

@lvl3 Thanks a lot for clarifying the problem and for the explanation of dour efforts! Would you like to create a PR where you add your remarks and explanations to the README of the extension? 😊

@lvl3
Copy link
Contributor

lvl3 commented Sep 3, 2021

@pantajoe Sure. I can do that. I'll try to replicate the issue on my other machine first to see what was the actual cause. It might take me a couple of days, but I'll try to do this during this week.

@pantajoe
Copy link
Owner

pantajoe commented Sep 3, 2021

@lvl3 Great, thank you. Very much appreciated!

@pantajoe
Copy link
Owner

pantajoe commented Sep 6, 2021

Steps to solve this problem locally are now in the README. Thanks again @lvl3!

@pantajoe pantajoe closed this as completed Sep 6, 2021
@sgobotta
Copy link

@pantajoe sorry to comment to a closed issue but seems to me the most appriopiate place. Does this work with workspaces that contain multiple elixir projects?
While I can configure User and Workspace settings I cannot do the same for opened folders in a workspace.

per/directory in workspace .json file:
image

settings per directory are not shown in the UI:

Shows on Workspace:
image

Does not show on Workspace folder:
image

@pantajoe
Copy link
Owner

pantajoe commented Nov 25, 2021

@sgobotta Yes, that should work. I introduced it a while ago. I published a new version (0.6.2) where you should be able to configure most settings within different folders of a workspace. Can you check if everything works fine now?

@sgobotta
Copy link

sgobotta commented Jun 9, 2022

@sgobotta Yes, that should work. I introduced it a while ago. I published a new version (0.6.2) where you should be able to configure most settings within different folders of a workspace. Can you check if everything works fine now?

I can't feel worse enough, sorry for the delay. Everything seems fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants