elm / error-message-catalog

A catalog of broken Elm programs / data to improve error messages
BSD 3-Clause "New" or "Revised" License
173 stars 17 forks source link

Whitespace before module definition - confusing error message #223

Open tad-lispy opened 7 years ago

tad-lispy commented 7 years ago

What's happening

Calling elm-make on a program that imports a module with whitespace before the module definition prints error that suggest's the declared module name is Main. E.g.:

The module name is messed up for ././View.elm

    According to the file's name it should be View
    According to the source code it should be Main

Which is it?

Steps to reproduce

In Bash compatible shell type / paste:

#! /usr/bin/env bash

echo "
module Main exposing (main)

import View
" > Main.elm

echo "
 module View -- note space at the beggining
" > View.elm

elm-make ./Main.elm

Expected result

There should be at least a hint about a whitespace in a fashion similar to #21. Or maybe it should be a syntax error to have whitespace at the beginning of first non-empty line of the program? Or error not to have module name declared - that would fit with Elm's apparent preference for explicitness. Just some quick ideas :)

Side notes

Interestingly running elm-make on the offending module itself:

elm make View.elm

gives a much better message:

-- SYNTAX PROBLEM ----------------------------------------------------- View.elm

I need a fresh line to start a new declaration. This means a new line that
starts with stuff, not with spaces or comments.

2|  module View
    ^
I am looking for one of the following things:

    whitespace

Detected errors in 1 module.
Maldus512 commented 6 years ago

Note that the same happens not with just the whitespace, but with any syntax error that happens during the module declaration. Writing

Module View
-- Note the uppercase 'M'

or even

anything that goes here is basically ignored View exposing(..)

Gives the same vague error message