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

Suggestion: Warn for "in" port without subscription #360

Open
Strepto opened this issue Nov 8, 2020 · 1 comment
Open

Suggestion: Warn for "in" port without subscription #360

Strepto opened this issue Nov 8, 2020 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@Strepto
Copy link

Strepto commented Nov 8, 2020

Expected Behavior

I would like to be warned that an "in port" would be stripped if no subscription is implemented.

Current Behavior

port module Main exposing (..)

-- Define an inPort (but no implementation yet)
port inPort : (String -> msg) -> Sub msg

subscriptions : Model -> Sub Msg
subscriptions _ =
    Sub.none -- inPort is never subscribed to

Currently the result of the elm compiler is to strip this port as it is never used in the Elm code, and when we are trying to send a message to the port app.ports.inPort.send("Hello"); we will get a runtime exception. The exception does not help us any way to understand "why" the exception occurs, as the port seemingly is spelled correctly in elm.

Example from my context:
image

Possible Solution

I think that if a warning (or even error) was added for unused "in ports" this would prevent bugs and googling, and possibly be quite cheap to implement as you already have usage tracking in the elm language server.

Context

I'm a beginner, trying to make ports do something for me one step at a time. I was stuck when I did not see why elm errored in the code in the screenshot above. I found this github issue for it, and figured it might help if this was implemented in the language server. elm/elm-lang.org#831

Feel free to close this if it is not relevant or too complicated.

Your Environment

  • Version used: Elm-Tooling v1.5.3
  • Editor used: VS Code
  • Environment name and version (e.g. node.js 5.4): Elm 19.1
  • Operating System and version: Windows 10
@Strepto Strepto changed the title Warn for "in" port without subscription Suggestion: Warn for "in" port without subscription Nov 8, 2020
@razzeee
Copy link
Member

razzeee commented Nov 8, 2020

Great idea, thanks for bringing this up.

@razzeee razzeee added enhancement New feature or request good first issue Good for newcomers labels Nov 8, 2020
@razzeee razzeee added this to the Backlog milestone Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants