purescript / registry-dev

Development work related to the PureScript Registry
https://github.com/purescript/registry
97 stars 80 forks source link

Fix duplicate module compilation failure #503

Closed thomashoneyman closed 2 years ago

thomashoneyman commented 2 years ago

When the compiler fails to build a package because of a duplicate module, the resulting error has no module name set. Our JSON decoding for these errors always expected a module name to be present, so instead of reporting a compilation failure we'd get an "unknown compiler error" and crash.

Here's what the JSON looks like for a duplicate module error:

{
  "warnings": [],
  "errors": [
    {
      "position": {
        "startLine": 1,
        "startColumn": 1,
        "endLine": 1,
        "endColumn": 18
      },
      "message": "  Module Main has been defined multiple times\n",
      "errorCode": "DuplicateModule",
      "errorLink": "https://github.com/purescript/documentation/blob/master/errors/DuplicateModule.md",
      "filename": "src/Main.purs",
      "moduleName": null,
      "suggestion": null
}

I've tested out this change, and duplicate module errors now properly report as compilation failures.