pantajoe / vscode-elixir-credo

VSCode support for Elixir Linter 'Credo'.

Home Page:https://marketplace.visualstudio.com/items?itemName=pantajoe.vscode-elixir-credo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Displaying of credo warnings throws "Illegal Argument" error

PJUllrich opened this issue · comments

My credo warnings weren't showing in the opened code file, but I knew there were some after running mix credo from the command line. So, I opened the Help > Toggle Developer Tools and saw that the following errors were logged:

mainThreadExtensionService.ts:59 [[object Object]]Illegal argument: character must be non-negative
$onExtensionRuntimeError @ mainThreadExtensionService.ts:59
_doInvokeHandler @ rpcProtocol.ts:417
_invokeHandler @ rpcProtocol.ts:402
_receiveRequest @ rpcProtocol.ts:318
_receiveOneMessage @ rpcProtocol.ts:245
(anonymous) @ rpcProtocol.ts:110
fire @ event.ts:622
fire @ ipc.net.ts:468
_receiveMessage @ ipc.net.ts:821
(anonymous) @ ipc.net.ts:660
fire @ event.ts:622
acceptChunk @ ipc.net.ts:241
(anonymous) @ ipc.net.ts:202
I @ ipc.net.ts:32
emit @ events.js:315
addChunk @ _stream_readable.js:295
readableAddChunk @ _stream_readable.js:271
Readable.push @ _stream_readable.js:212
onStreamRead @ internal/stream_base_commons.js:186

mainThreadExtensionService.ts:60 Error: Illegal argument: character must be non-negative
	at Object.k [as illegalArgument] (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:5)
	at new m (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:81)
	at new m (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:81)
	at new S (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:81)
	at new S (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:81)
	at Function.parseCredoIssue (/Users/pullrich/.vscode/extensions/pantajoe.vscode-elixir-credo-0.2.0/out/CredoParser.js:18)
	at /Users/pullrich/.vscode/extensions/pantajoe.vscode-elixir-credo-0.2.0/out/CredoParser.js:8
	at Array.map (<anonymous>)
	at Function.parseCredoOutput (/Users/pullrich/.vscode/extensions/pantajoe.vscode-elixir-credo-0.2.0/out/CredoParser.js:8)
	at /Users/pullrich/.vscode/extensions/pantajoe.vscode-elixir-credo-0.2.0/out/CredoProvider.js:34
	at ChildProcess.exithandler (child_process.js:319)
	at ChildProcess.emit (events.js:315)
	at maybeClose (internal/child_process.js:1021)
	at Socket.<anonymous> (internal/child_process.js:443)
	at Socket.emit (events.js:315)
	at Pipe.<anonymous> (net.js:674)

The credo warning that should have been shown here was the following:

Web.StripeWebhookController                                                                                                                                          
┃ 
┃   [W] Category: warning 
┃    ↗  Priority: high 
┃ 
┃       Module attribute @webhook_signing_key makes use of unsafe Application configuration call Application.get_env/2
┃       lib/web/controllers/stripe_webhook/stripe_webhook_controller.ex:6 (Web.StripeWebhookController)
┃ 
┃    __ CODE IN QUESTION
┃ 
┃     4   require Logger
┃     5 
┃     6   @webhook_signing_key Application.get_env(:stripity_stripe, :webhook_signing_key)
┃       
┃    __ WHY IT MATTERS
┃ 
┃       Module attributes are evaluated at compile time and not at run time. As
┃       a result, certain configuration read calls made in your module attributes
┃       may work as expected during local development, but may break once in a
┃       deployed context.
┃       
┃       This check analyzes all of the module attributes present within a module,
┃       and validates that there are no unsafe calls.
┃       
┃       These unsafe calls include:
┃       
┃       - `Application.fetch_env/2`
┃       - `Application.fetch_env!/2`
┃       - `Application.get_all_env/1`
┃       - `Application.get_env/3`
┃       - `Application.get_env/2`
┃       
┃       As of Elixir 1.10 you can leverage `Application.compile_env/3` and
┃       `Application.compile_env!/2` if you wish to set configuration at
┃       compile time using module attributes.
┃ 
┃    __ CONFIGURATION OPTIONS
┃ 
┃       You can disable this check by using this tuple
┃ 
┃         {Credo.Check.Warning.ApplicationConfigInModuleAttribute, false}
┃ 
┃       There are no other configuration options.
┃ 
┃                                                          

I'm not entirely sure why displaying this warning threw an error unfortunately. Can I help you somehow with replicating this error maybe?

Hey! Uh, that is not supposed to happen 😄 Thanks for pointing out that issue. It would be great if you could send me the output of the command mix credo --format json in your workspace. Then, I'll probably be able to fix this issue quite quickly.

Of course! Here's the warning in json format:

{
      "category": "warning",
      "check": "Credo.Check.Warning.ApplicationConfigInModuleAttribute",
      "column": null,
      "column_end": null,
      "filename": "lib/web/controllers/stripe_webhook/stripe_webhook_controller.ex",
      "line_no": 6,
      "message": "Module attribute @webhook_signing_key makes use of unsafe Application configuration call Application.get_env/2",
      "priority": 11,
      "scope": "Web.StripeWebhookController",
      "trigger": "Application.get_env/2"
    }

The warning references a module attribute. It looks something like this:

defmodule StripeWebhookController do

  @webhook_signing_key Application.get_env(:my_app, :webhook_signing_key)

   # ... Other module stuff ...

end

Thank you for having a look at this 🙏

Turns out, this was a stupid typo 😄
Anyway, i improved the highlight ranges of issues that yield a trigger.
I release a new version that fixes this issue and I'll close this issue for now.