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

"failed to decode PsaResult" when purs compile exits due to OOM #1284

Open
cakekindel opened this issue Sep 13, 2024 · 2 comments · May be fixed by #1285
Open

"failed to decode PsaResult" when purs compile exits due to OOM #1284

cakekindel opened this issue Sep 13, 2024 · 2 comments · May be fixed by #1285
Labels

Comments

@cakekindel
Copy link
Contributor

Spent several hours yesterday trying to figure out why my ci job running spago build / spago test was failing despite nothing visibly changing in the environment, and the purs compile step exiting at random points in the build with:

$ spago build --pure --strict --pedantic-packages && bun run scripts/fmt.js --check
Reading Spago workspace configuration...
✓ Selecting 13 packages to build:
    <snip>
Downloading dependencies...
Refreshing the Registry Index...
Building...
[  1 of 941] Compiling Unsafe.Coerce
[  2 of 941] Compiling Web.Event.Internal.Types
[  4 of 941] Compiling Type.Proxy
[  3 of 941] Compiling Web.DOM.Internal.Types
[  5 of 941] Compiling Type.Function
[  6 of 941] Compiling Type.Equality
[  7 of 941] Compiling Type.Row
<snip>
[xxx of 941] Compiling xxx
‼ Failed to decode PsaResult at index '0': Unexpected end of JSON input
Json was: 
✓ Build succeeded.

Eventually I had the thought "maybe the --memory=1G I added to the runner is making purs compile exit early" which turned out to be exactly the case. Not sure if this is necessarily a bug in spago, just documenting this as an issue here for people who run into this in the future.

@cakekindel
Copy link
Contributor Author

Weird so we do catch non-ok exit cases
src/Spago/Cmd.purs#L110. Not sure what else we could do to trap this

@f-f
Copy link
Member

f-f commented Sep 14, 2024

Ah, it turns out we're not checking the exit status when trying to decode the compiler output in the psa machinery, see here:

spago/src/Spago/Psa.purs

Lines 43 to 50 in b7c0483

result <- Purs.compile globs (Array.snoc pursArgs "--json-errors")
let resultStdout = Cmd.getStdout result
arrErrorsIsEmpty <- forWithIndex (Str.split (Str.Pattern "\n") resultStdout) \idx err ->
case JSON.parse err >>= CJ.decode psaResultCodec >>> lmap CJ.DecodeError.print of
Left decodeErrMsg -> do
logWarn $ Array.intercalate "\n"
[ "Failed to decode PsaResult at index '" <> show idx <> "': " <> decodeErrMsg
, "Json was: " <> err

In line 44 we call getStdout (which I think is an antipattern and should only be used in tests) without first checking if result is a Left or a Right. I suspect that when the compiler fails we get the error on stderr and stdout is empty, but we still try to decode it.

@f-f f-f added the bug label Sep 14, 2024
@cakekindel cakekindel linked a pull request Sep 16, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants