purescript / registry-dev

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

Fix `CompilerError` decoding in 0.13.x series of purs #635

Closed colinwahl closed 1 year ago

colinwahl commented 1 year ago

While working on #255, @thomashoneyman noticed some log lines reporting unknown compiler errors, like

[STDOUT]
Compiling Data.NaturalTransformation
Compiling Data.Boolean
Compiling Data.Show
Compiling Control.Semigroupoid
Compiling Control.Category
Compiling Data.Unit
Compiling Data.Void
Compiling Data.Semiring
Compiling Data.HeytingAlgebra
Compiling Data.Semigroup
Compiling Data.Eq
Compiling Data.Ring
Compiling Data.BooleanAlgebra
Compiling Data.Ordering
Compiling Data.CommutativeRing
Compiling Data.EuclideanRing
Compiling Data.Ord.Unsafe
Compiling Data.Ord
Compiling Data.DivisionRing
Compiling Data.Field
Compiling Data.Bounded
Compiling Data.Function
Compiling Data.Functor
Compiling Control.Apply
Compiling Control.Applicative
Compiling Control.Bind
Compiling Control.Monad
Compiling Prelude
Compiling Debug.Trace
[STDERR]
{"warnings":[],"errors":[{"position":{"startLine":8,"startColumn":1,"endLine":8,"endColumn":58},"message":"  Unknown type class Warn\n","errorCode":"UnknownName","errorLink":"https://github.com/purescript/documentation/blob/master/errors/UnknownName.md","filename":"/run/user/1000/tmp-714974-ghvoRncaz00A/.registry/debug-3.0.0/src/Debug/Trace.purs","moduleName":"Debug.Trace","suggestion":null,"allSpans":[{"start":[8,1],"name":"/run/user/1000/tmp-714974-ghvoRncaz00A/.registry/debug-3.0.0/src/Debug/Trace.purs","end":[8,58]}]}]}
[DECODE ERROR]
An error occurred while decoding a JSON value:
  Expected value of type 'JSON: Unexpected token C in JSON at position 0'.

It turns out that starting in 0.14.0, compiler errors were switched to being reported to stdout, whereas they used to be in stderr: https://github.com/purescript/purescript/releases/tag/v0.14.0

This PR changes CompilerArgs to take a Version, so we can check that we can get proper Version Ord and check compiler versions before deciding where to try to parse the compiler errors from, and propagates the changes needed to make that typecheck. It also adds tests to catch this case.

thomashoneyman commented 1 year ago

That explains it! 😂