Skip to content

toSnippet shouldn't crash if the error has no source code#362

Merged
robinheghan merged 1 commit intogren-lang:mainfrom
gilramir:empty-deps-crash-issue-360
Jan 26, 2026
Merged

toSnippet shouldn't crash if the error has no source code#362
robinheghan merged 1 commit intogren-lang:mainfrom
gilramir:empty-deps-crash-issue-360

Conversation

@gilramir
Copy link
Contributor

Fixes #360

A "MODULE NOT FOUND" error may be due to the default "import" statements the compiler adds to Gren source code (like, "import Basics"), if gren.json doesn't contain "gren-lang/core".

In this case, there is no faulty source code region to report, so toSnippet should recognize this and avoid crashing when trying to render it.

Before this change, the compiler would crash:

Compiling ...-- MODULE NOT FOUND ------------------------------------------- src/Example.gren

Detected problems in 1 module.
gren: Prelude.last: empty list
CallStack (from HasCallStack):
  error, called at libraries/base/GHC/List.hs:2004:3 in base:GHC.List
  errorEmptyList, called at libraries/base/GHC/List.hs:212:13 in base:GHC.List
  lastError, called at libraries/base/GHC/List.hs:207:29 in base:GHC.List
  last, called at compiler/src/Reporting/Render/Code.hs:98:28 in gren-0.6.3-inplace-common:Reporting.Render.Code

With this fix, an error is correctly reported for every default module that cannot be imported. E.g.:

You are trying to import a `Basics` module:

I checked the "dependencies" and "source-directories" listed in your gren.json,
but I cannot find it! Maybe it is a typo for one of these names?

    Example

Hint: If it is not a typo, check the "dependencies" and "source-directories" of
your gren.json to make sure all the packages you need are listed there!

Fixes gren-lang#360

A "MODULE NOT FOUND" error may be due to the default "import"
statements the compiler adds to Gren source code (like,
"import Basics"), if gren.json doesn't contain "gren-lang/core".

In this case, there is no faulty source code region to report,
so toSnippet should recognize this and avoid crashing when
trying to render it.
@robinheghan robinheghan merged commit 9123599 into gren-lang:main Jan 26, 2026
4 of 5 checks passed
@robinheghan
Copy link
Member

Thank you

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

Successfully merging this pull request may close these issues.

compiler crashes if "direct" dependencies in gren.json is empty

2 participants