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

Fix encoding issues: use with-utf8 library and other tricks #595

Merged
merged 8 commits into from
Mar 29, 2020

Conversation

f-f
Copy link
Member

@f-f f-f commented Mar 13, 2020

Thanks to @jamesdbrock yesterday I discovered the with-utf8 library, which tagline is "Get your IO right on the first try"

There's an excellent blogpost about the rationale and the implementation, and it looks like putting the library into use might fix all the encoding problems we're facing here in Spago when dealing with encodings different than UTF8.

@bbarker @kakkun61 @gibranrosa could you try building Spago from this branch to see if this fixes your issues?

Fix #533
Fix #507
Close #576

@gibranrosa
Copy link
Contributor

Hi @f-f !
Thanks for the try, but unfortunately it does not fixed totally. Curiously the Spago Init command works now, but Spago build doesn't, and with the first workaround, the deletion of UTF8 fixation, the reverse happens, build works and init does not.
Spago Build error:
�[34m[info] �[0mInstallation complete.�[0m
spago-utf8: fd:5: hGetContents: invalid argument (invalid byte sequence)

@f-f
Copy link
Member Author

f-f commented Mar 18, 2020

@gibranrosa thank you for trying this out! It sounds like we're a little bit closer to a solution.

Some questions:

  • with this branch init works but build doesn't. What's the result with the currently published version?
  • could you describe your environment? E.g. OS, locale, etc
  • is there any way you could reproduce (or approximate) your local environment with a Nix file or a Docker container? Having a reproducible setup would be the best help we could have to figure out how to fix this - because once we have a repro then we can setup a test for it.

@gibranrosa
Copy link
Contributor

@gibranrosa thank you for trying this out! It sounds like we're a little bit closer to a solution.

Some questions:

* with this branch `init` works but `build` doesn't. What's the result with the currently published version?

* could you describe your environment? E.g. OS, locale, etc

* is there any way you could reproduce (or approximate) your local environment with a Nix file or a Docker container? Having a reproducible setup would be the best help we could have to figure out how to fix this - because once we have a repro then we can setup a test for it.
  1. Tested with the published version, and the result is the same as with this Branch version, so it appears this change had no effect, unfortunately.

  2. Windows 10 , pt-BR, the default encoding by Powershell:
    IsSingleByte : True
    BodyName : iso-8859-1
    EncodingName : Europa Ocidental (Windows)
    HeaderName : Windows-1252
    WebName : Windows-1252
    WindowsCodePage : 1252

  3. I've never used Docker, and Nix very little, but I can try to learn and make a repro setup. Or maybe @bbarker or @kakkun61 could do it.

@f-f
Copy link
Member Author

f-f commented Mar 18, 2020

@gibranrosa thank you! Could you post here the output of spago -V build?

@gibranrosa
Copy link
Contributor

gibranrosa commented Mar 18, 2020

spago -V build:

�[90m2020-03-18 13:29:32.450918: �[32m[debug] �[0mRunning `getGlobalCacheDir`�[90m
@(app\Spago.hs:399:7)�[0m
�[90m2020-03-18 13:29:32.466547: �[32m[debug] �[0mRunning `spago build`�[90m
@(src\Spago\Build.hs:95:3)�[0m
�[90m2020-03-18 13:29:33.122883: �[32m[debug] �[0mTransformed config is the same as the read one, not overwriting it�[90m
@(src\Spago\Config.hs:374:14)�[0m
�[90m2020-03-18 13:29:37.654518: �[32m[debug] �[0mEnsuring that the package set is frozen�[90m
@(src\Spago\PackageSet.hs:268:3)�[0m
�[90m2020-03-18 13:29:37.685766: �[32m[debug] �[0mGetting transitive deps�[90m
@(src\Spago\Packages.hs:136:3)�[0m
�[90m2020-03-18 13:29:37.685766: �[32m[debug] �[0mRunning `fetchPackages`�[90m
@(src\Spago\FetchPackage.hs:44:3)�[0m
�[90m2020-03-18 13:29:37.685766: �[32m[debug] �[0mChecking if `purs` is up to date�[90m
@(src\Spago\PackageSet.hs:178:3)�[0m
�[90m2020-03-18 13:29:42.264081: �[34m[info] �[0mInstalling 56 dependencies.�[90m
@(src\Spago\FetchPackage.hs:63:5)�[0m
�[90m2020-03-18 13:29:42.264081: �[32m[debug] �[0mRunning `getMetadata`�[90m
@(src\Spago\GlobalCache.hs:88:3)�[0m
�[90m2020-03-18 13:29:42.264081: �[32m[debug] �[0mGlobal cache directory: "C:\\Users\\Gibran2\\AppData\\Local\\spago"�[90m
@(src\Spago\GlobalCache.hs:92:3)�[0m
�[90m2020-03-18 13:29:42.264081: �[34m[info] �[0mSearching for packages cache metadata..�[90m
@(src\Spago\GlobalCache.hs:128:7)�[0m
�[90m2020-03-18 13:29:42.295331: �[34m[info] �[0mRecent packages cache metadata found, using it..�[90m
@(src\Spago\GlobalCache.hs:134:11)�[0m
�[90m2020-03-18 13:29:42.576572: �[32m[debug] �[0mFetching package aff�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.576572: �[32m[debug] �[0mFetching package enums�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.592197: �[32m[debug] �[0mFetching package aff-promise�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.685946: �[32m[debug] �[0mFetching package exceptions�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.685946: �[32m[debug] �[0mFetching package bifunctors�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.764067: �[32m[debug] �[0mFetching package exists�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.764067: �[32m[debug] �[0mFetching package console�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.779692: �[32m[debug] �[0mFetching package foldable-traversable�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.826565: �[32m[debug] �[0mFetching package contravariant�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.826565: �[32m[debug] �[0mFetching package datetime�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.826565: �[32m[debug] �[0mFetching package foreign�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.842189: �[32m[debug] �[0mFetching package distributive�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.842189: �[32m[debug] �[0mFetching package foreign-generic�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.873440: �[32m[debug] �[0mFetching package either�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.873440: �[32m[debug] �[0mFetching package arrays�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.873440: �[32m[debug] �[0mFetching package control�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.873440: �[32m[debug] �[0mFetching package catenable-lists�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.873440: �[32m[debug] �[0mFetching package const�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.951561: �[32m[debug] �[0mFetching package effect�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.951561: �[32m[debug] �[0mFetching package debug�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:42.982811: �[34m[info] �[0mCopying from global cache: "aff"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:42.982811: �[34m[info] �[0mCopying from global cache: "aff-promise"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:42.982811: �[34m[info] �[0mCopying from global cache: "enums"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:43.170303: �[34m[info] �[0mCopying from global cache: "bifunctors"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:43.170303: �[34m[info] �[0mCopying from global cache: "exceptions"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:43.357799: �[34m[info] �[0mCopying from global cache: "foldable-traversable"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:43.482794: �[34m[info] �[0mCopying from global cache: "exists"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:43.482794: �[34m[info] �[0mCopying from global cache: "console"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:43.482794: �[34m[info] �[0mCopying from global cache: "contravariant"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:43.498418: �[34m[info] �[0mCopying from global cache: "datetime"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:43.607789: �[34m[info] �[0mCopying from global cache: "foreign"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:43.670288: �[34m[info] �[0mCopying from global cache: "distributive"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:43.701537: �[34m[info] �[0mCopying from global cache: "foreign-generic"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:43.826533: �[34m[info] �[0mCopying from global cache: "arrays"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:44.170272: �[34m[info] �[0mCopying from global cache: "catenable-lists"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:44.185898: �[34m[info] �[0mCopying from global cache: "control"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:44.217147: �[34m[info] �[0mCopying from global cache: "either"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:44.232770: �[34m[info] �[0mCopying from global cache: "effect"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:44.232770: �[34m[info] �[0mCopying from global cache: "debug"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:44.404640: �[34m[info] �[0mCopying from global cache: "const"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:46.745950: �[32m[debug] �[0mFetching package foreign-object�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:47.152188: �[34m[info] �[0mCopying from global cache: "foreign-object"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:48.261608: �[32m[debug] �[0mFetching package free�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:48.261608: �[34m[info] �[0mCopying from global cache: "free"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:48.308481: �[32m[debug] �[0mFetching package functions�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:48.589807: �[34m[info] �[0mCopying from global cache: "functions"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:48.652306: �[32m[debug] �[0mFetching package functors�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:48.730429: �[32m[debug] �[0mFetching package gen�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:48.808551: �[32m[debug] �[0mFetching package generics-rep�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:48.808551: �[34m[info] �[0mCopying from global cache: "gen"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:48.902297: �[34m[info] �[0mCopying from global cache: "functors"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:49.199165: �[32m[debug] �[0mFetching package globals�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:49.574247: �[34m[info] �[0mCopying from global cache: "generics-rep"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:49.746116: �[34m[info] �[0mCopying from global cache: "globals"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:49.855488: �[32m[debug] �[0mFetching package identity�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:49.871112: �[32m[debug] �[0mFetching package invariant�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:49.964860: �[32m[debug] �[0mFetching package integers�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:50.089856: �[34m[info] �[0mCopying from global cache: "identity"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:50.261725: �[32m[debug] �[0mFetching package lazy�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:50.386722: �[34m[info] �[0mCopying from global cache: "invariant"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:50.683694: �[34m[info] �[0mCopying from global cache: "integers"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:50.824314: �[34m[info] �[0mCopying from global cache: "lazy"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:50.855563: �[32m[debug] �[0mFetching package lists�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:51.308674: �[32m[debug] �[0mFetching package math�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:52.121230: �[34m[info] �[0mCopying from global cache: "lists"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:52.121230: �[34m[info] �[0mCopying from global cache: "math"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:52.246226: �[32m[debug] �[0mFetching package maybe�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:52.418097: �[32m[debug] �[0mFetching package newtype�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:52.449346: �[34m[info] �[0mCopying from global cache: "newtype"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:52.449346: �[32m[debug] �[0mFetching package nonempty�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:52.449346: �[34m[info] �[0mCopying from global cache: "nonempty"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:52.668166: �[34m[info] �[0mCopying from global cache: "maybe"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:53.324400: �[32m[debug] �[0mFetching package options�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:53.324400: �[34m[info] �[0mCopying from global cache: "options"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:53.355646: �[32m[debug] �[0mFetching package ordered-collections�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:53.355646: �[34m[info] �[0mCopying from global cache: "ordered-collections"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:55.980772: �[32m[debug] �[0mFetching package orders�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:55.980772: �[34m[info] �[0mCopying from global cache: "orders"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:56.090144: �[32m[debug] �[0mFetching package parallel�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:57.043444: �[34m[info] �[0mCopying from global cache: "parallel"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:57.277811: �[32m[debug] �[0mFetching package partial�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:58.277901: �[32m[debug] �[0mFetching package prelude�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:58.449773: �[32m[debug] �[0mFetching package proxy�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:58.512268: �[32m[debug] �[0mFetching package psci-support�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:58.590464: �[32m[debug] �[0mFetching package record�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:58.871708: �[32m[debug] �[0mFetching package refs�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:58.871708: �[32m[debug] �[0mFetching package sequelize�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:59.106071: �[34m[info] �[0mCopying from global cache: "prelude"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:59.465437: �[34m[info] �[0mCopying from global cache: "partial"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:59.465437: �[32m[debug] �[0mFetching package st�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:59.559283: �[34m[info] �[0mCopying from global cache: "proxy"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:59.809277: �[34m[info] �[0mCopying from global cache: "psci-support"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:59.809277: �[32m[debug] �[0mFetching package strings�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:29:59.981146: �[34m[info] �[0mCopying from global cache: "record"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:29:59.981146: �[34m[info] �[0mCopying from global cache: "refs"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:30:00.121766: �[34m[info] �[0mCopying from global cache: "st"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:30:00.590632: �[32m[debug] �[0mFetching package tailrec�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:30:00.715628: �[32m[debug] �[0mRunning `globallyCache`: PackageName {packageName = "sequelize"} https://github.com/gibranrosa/purescript-sequelize.git compiler/0.13�[90m
@(src\Spago\GlobalCache.hs:55:3)�[0m
�[90m2020-03-18 13:30:00.746881: �[32m[debug] �[0mFetching package transformers�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:30:01.153115: �[34m[info] �[0mCopying from global cache: "strings"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:30:01.278109: �[34m[info] �[0mCopying from global cache: "tailrec"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:30:01.512478: �[34m[info] �[0mCopying from global cache: "transformers"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:30:02.106212: �[32m[debug] �[0mFetching package tuples�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:30:02.106212: �[34m[info] �[0mCopying from global cache: "tuples"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:30:03.043839: �[34m[info] �[0mInstalling "sequelize"�[90m
@(src\Spago\FetchPackage.hs:138:15)�[0m
�[90m2020-03-18 13:30:05.856556: �[32m[debug] �[0mFetching package type-equality�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:30:05.856556: �[34m[info] �[0mCopying from global cache: "type-equality"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:30:06.262789: �[32m[debug] �[0mFetching package typelevel-prelude�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:30:06.262789: �[34m[info] �[0mCopying from global cache: "typelevel-prelude"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:30:06.294039: �[32m[debug] �[0mFetching package unfoldable�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:30:07.075344: �[32m[debug] �[0mFetching package unsafe-coerce�[90m
@(src\Spago\FetchPackage.hs:100:3)�[0m
�[90m2020-03-18 13:30:07.606704: �[34m[info] �[0mCopying from global cache: "unfoldable"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:30:07.684828: �[34m[info] �[0mCopying from global cache: "unsafe-coerce"�[90m
@(src\Spago\FetchPackage.hs:114:9)�[0m
�[90m2020-03-18 13:30:20.749128: �[34m[info] �[0mInstallation complete.�[90m
@(src\Spago\FetchPackage.hs:71:3)�[0m
spago-original: fd:5: hGetContents: invalid argument (invalid byte sequence)

@gibranrosa
Copy link
Contributor

Just to register that I've found a Windows setting to make UTF-8 the default, and thus all works fine, but it is a Beta setting yet, and there is known bugs with this enabled.

It's in Control Panel > Region > Administrative

Here is the SuperUser answer explaining:
https://superuser.com/a/1451686

@gibranrosa
Copy link
Contributor

gibranrosa commented Mar 18, 2020

I was narrowing down the error putting logDebugs and apparently the exception occurs at Purs.hs, line 135, in the call to shellStrictWithErr from Turtle library. Below the logs I put and below that the Spago buid log:

versionImpl :: Text -> Spago (Either Text Version.SemVer)
versionImpl purs = do 
  logDebug "passed Purs.compile - Enters versionImpl"  -- <--- Terminates here
  shellStrictWithErr (purs <> " --version") empty >>= \case
    (ExitSuccess, out, _err) -> do
      logDebug "passed Purs.compile - versionImpl"
      let versionText = headMay $ Text.split (== ' ') out
          parsed = versionText >>= (hush . Version.semver)
      logDebug "passed Purs.compile - versionImpl - pass versionText"
      pure $ case parsed of
        Nothing -> Left $ Messages.failedToParseCommandOutput (purs <> " --version") out
        Just p -> Right p
    (_, _out, _err) -> do
      logDebug "passed Purs.compile - versionImpl - Err case"
      pure $ Left $ "Failed to run '" <> purs <> " --version'"
�[90m2020-03-18 15:30:05.612807: �[32m[debug] �[0mRunning `getGlobalCacheDir`�[90m
@(app\Spago.hs:406:7)�[0m
�[90m2020-03-18 15:30:05.619802: �[32m[debug] �[0mRunning `spago build`�[90m
@(src\Spago\Build.hs:96:3)�[0m
�[90m2020-03-18 15:30:05.651783: �[32m[debug] �[0mTransformed config is the same as the read one, not overwriting it�[90m
@(src\Spago\Config.hs:374:14)�[0m
�[90m2020-03-18 15:30:05.970587: �[32m[debug] �[0mEnsuring that the package set is frozen�[90m
@(src\Spago\PackageSet.hs:268:3)�[0m
�[90m2020-03-18 15:30:06.017558: �[32m[debug] �[0mGetting transitive deps�[90m
@(src\Spago\Packages.hs:136:3)�[0m
�[90m2020-03-18 15:30:06.045541: �[32m[debug] �[0mRunning `fetchPackages`�[90m
@(src\Spago\FetchPackage.hs:44:3)�[0m
�[90m2020-03-18 15:30:06.050538: �[32m[debug] �[0mChecking if `purs` is up to date�[90m
@(src\Spago\PackageSet.hs:178:3)�[0m
�[90m2020-03-18 15:30:06.056532: �[32m[debug] �[0mpassed Purs.compile - Enters versionImpl�[90m
@(src\Spago\Purs.hs:134:3)�[0m
�[90m2020-03-18 15:30:06.135484: �[32m[debug] �[0mpassed Purs.compile - versionImpl�[90m
@(src\Spago\Purs.hs:137:7)�[0m
�[90m2020-03-18 15:30:06.140481: �[32m[debug] �[0mpassed Purs.compile - versionImpl - pass versionText�[90m
@(src\Spago\Purs.hs:140:7)�[0m
�[90m2020-03-18 15:30:06.158471: �[34m[info] �[0mInstallation complete.�[90m
@(src\Spago\FetchPackage.hs:71:3)�[0m
�[90m2020-03-18 15:30:06.163466: �[32m[debug] �[0mpassed getBuildArgsForSharedFolder�[90m
@(src\Spago\Build.hs:105:3)�[0m
�[90m2020-03-18 15:30:06.168463: �[32m[debug] �[0mpassed lets getGlobs�[90m
@(src\Spago\Build.hs:139:3)�[0m
�[90m2020-03-18 15:30:06.173461: �[32m[debug] �[0mpassed call buildAction�[90m
@(src\Spago\Build.hs:142:9)�[0m
�[90m2020-03-18 15:30:06.179456: �[32m[debug] �[0mpassed buildAction - beforeCommands�[90m
@(src\Spago\Build.hs:133:9)�[0m
�[90m2020-03-18 15:30:06.186452: �[32m[debug] �[0mpassed call Purs.compile�[90m
@(src\Spago\Build.hs:112:15)�[0m
�[90m2020-03-18 15:30:06.193450: �[32m[debug] �[0mpassed enters Purs.compile�[90m
@(src\Spago\Purs.hs:40:3)�[0m
�[90m2020-03-18 15:30:06.198445: �[32m[debug] �[0mpassed Purs.compile - view usePsaL�[90m
@(src\Spago\Purs.hs:42:3)�[0m
�[90m2020-03-18 15:30:06.204441: �[32m[debug] �[0mpassed Purs.compile - usePsa - call psaVersion�[90m
@(src\Spago\Purs.hs:46:7)�[0m
�[90m2020-03-18 15:30:06.211437: �[32m[debug] �[0mpassed Purs.compile - Enters versionImpl�[90m
@(src\Spago\Purs.hs:134:3)�[0m
spago.exe: fd:5: hGetContents: invalid argument (invalid byte sequence)

@gibranrosa
Copy link
Contributor

gibranrosa commented Mar 18, 2020

Continuing the debugging, I've found setting the encoding to latin1 (win-1252) right before shellStrictWithErr and resetting to UTF8 right after works too:

versionImpl :: Text -> Spago (Either Text Version.SemVer)
versionImpl purs = do 
  logDebug "passed Purs.compile - Enters versionImpl"
  liftIO $ GHC.IO.Encoding.setLocaleEncoding GHC.IO.Encoding.latin1
  shellStrictWithErr (purs <> " --version") empty >>= \case
    (ExitSuccess, out, _err) -> do
      liftIO $ GHC.IO.Encoding.setLocaleEncoding GHC.IO.Encoding.utf8
      logDebug "passed Purs.compile - versionImpl"
      let versionText = headMay $ Text.split (== ' ') out
          parsed = versionText >>= (hush . Version.semver)
      logDebug "passed Purs.compile - versionImpl - pass versionText"
      pure $ case parsed of
        Nothing -> Left $ Messages.failedToParseCommandOutput (purs <> " --version") out
        Just p -> Right p
    (_, _out, _err) -> do
      logDebug "passed Purs.compile - versionImpl - Err case"
      pure $ Left $ "Failed to run '" <> purs <> " --version'"

@f-f
Copy link
Member Author

f-f commented Mar 18, 2020

@gibranrosa great debugging! It looks like shellStrictWithErr is calling Text.hGetContents, which apparently gets the decoding wrong. Could you try seeing if using Turtle.Bytes.shellStrictWithErr fixes this?
This one returns ByteStrings, which make us safe from encoding errors while reading the file, and leave us the ability to use Data.Text.Encoding.decodeUtf8With to get a Text again

@gibranrosa
Copy link
Contributor

gibranrosa commented Mar 18, 2020

@f-f Thanks!
It worked! But I've used decodeUtf8 to convert from ByteString to Text as follows, do you think it can be problematic?
Edit: I've used decoteUtf8With with lenientDecode, is that OK?

Here is the commit in my fork: gibranrosa@b446506

versionImpl purs = do 
  Turtle.Bytes.shellStrictWithErr (purs <> " --version") empty >>= \case
    (ExitSuccess, out, _err) -> do
      let versionText = headMay $ Text.split (== ' ') (Text.Encoding.decodeUtf8With lenientDecode out)
          parsed = versionText >>= (hush . Version.semver)
      pure $ case parsed of
        Nothing -> Left $ Messages.failedToParseCommandOutput (purs <> " --version") (Text.Encoding.decodeUtf8With lenientDecode out)
        Just p -> Right p
    (_, _out, _err) -> do
      pure $ Left $ "Failed to run '" <> purs <> " --version'"

@kakkun61
Copy link

kakkun61 commented Mar 20, 2020

I tried to compile my application kakkun61/elm-license-checker@5517b19, and then I got the following log.

λ  npx spago -V build
2020-03-20 13:02:01.562297: [debug] Running `getGlobalCacheDir`
@(app\Spago.hs:406:7)
2020-03-20 13:02:01.578297: [debug] Running `spago build`
@(src\Spago\Build.hs:96:3)
2020-03-20 13:02:01.608297: [debug] Transformed config is the same as the read one, not overwriting it
@(src\Spago\Config.hs:374:14)
2020-03-20 13:02:01.658297: [debug] Ensuring that the package set is frozen
@(src\Spago\PackageSet.hs:268:3)
2020-03-20 13:02:01.702298: [debug] Getting transitive deps
@(src\Spago\Packages.hs:136:3)
2020-03-20 13:02:01.717300: [debug] Running `fetchPackages`
@(src\Spago\FetchPackage.hs:44:3)
2020-03-20 13:02:01.734297: [debug] Checking if `purs` is up to date
@(src\Spago\PackageSet.hs:178:3)
2020-03-20 13:02:01.814307: [info] Installation complete.
@(src\Spago\FetchPackage.hs:71:3)
spago: fd:5: hGetContents: invalid argument (invalid byte sequence)

My environment is:

  • Windows 10 1909
  • PowerShell 5.1.18362.628
  • locale (code point) 932
PowerShell version details
λ  $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.18362.628
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.18362.628
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

@gibranrosa
Copy link
Contributor

@kakkun61 Could you try the build with the fix I did with the help from @f-f ?
Here is the link to the release containing the exe built with this fix: https://github.com/gibranrosa/spago/releases/tag/0.14-windows10-fix

@wangbinyq
Copy link

@kakkun61 Could you try the build with the fix I did with the help from @f-f ?
Here is the link to the release containing the exe built with this fix: https://github.com/gibranrosa/spago/releases/tag/0.14-windows10-fix

It works on my pc with code point 936 (GBK).

@kakkun61
Copy link

Oh, I had done with this #595.

I tried https://github.com/gibranrosa/spago/releases/tag/0.14-windows10-fix, and I got no error!

λ  npx spago build -v
[debug] Running `getGlobalCacheDir`
[debug] Running `spago build`
[debug] Transformed config is the same as the read one, not overwriting it
[debug] Ensuring that the package set is frozen
[debug] Getting transitive deps
[debug] Running `fetchPackages`
[debug] Checking if `purs` is up to date
[info] Installation complete.
[debug] Failed to run 'psa --version'
[debug] Compiling with "purs"
[debug] Running command: `purs compile  …`
[info] Build succeeded.

@f-f
Copy link
Member Author

f-f commented Mar 26, 2020

Alright, it looks like we're on a good path! Thanks @gibranrosa for the fix (which I cherry-picked in this branch, but feel free to PR it already to the master branch) and to @kakkun61 and @wangbinyq for testing 🙂

I'm going to try changing the Windows build to run with Japanese encoding, to see if we can spot any tests failing. In the meanwhile you could also try running stack test with this branch and see if you spot any failures on your machine that we might be missing otherwise

@gibranrosa
Copy link
Contributor

I've ran the tests and there is some errors that does not look related to this change, right?

Failures:

  test\BumpVersionSpec.hs:141:61:
  1) BumpVersion, spago bump-version, end to end tests, Spago should only make a tag with `--no-dry-run`
       predicate failed on: (ExitFailure 1,"","\ESC[34m[info] \ESC[0mGenerating a new Bower config using the package set versions..\ESC[0m\n\ESC[34m[info] \ESC[0mGenerated a valid Bower config using the package set\ESC[0m\n\ESC[34m[info] \ESC[0mFound current version from git tag: v1.2.3\ESC[0m\n\ESC[34m[info] \ESC[0m** Running action: write the new config to the `bower.json` file and try to install its dependencies\ESC[0m\n\ESC[34m[info] \ESC[0mWriting the new Bower config to \"bower.json\"\ESC[0m\n\ESC[34m[info] \ESC[0mRunning `bower install` so `pulp publish` can read resolved versions from it\ESC[0m\n\ESC[31m[error] \ESC[0mA new bower.json has been generated. Please commit this and run `bump-version` again.\ESC[0m\n")

  To rerun use: --match "/BumpVersion/spago bump-version/end to end tests/Spago should only make a tag with `--no-dry-run`/"

  test\BumpVersionSpec.hs:146:61:
  2) BumpVersion, spago bump-version, end to end tests, Spago should use v0.0.0 as initial version
       predicate failed on: (ExitFailure 1,"","\ESC[34m[info] \ESC[0mGenerating a new Bower config using the package set versions..\ESC[0m\n\ESC[34m[info] \ESC[0mGenerated a valid Bower config using the package set\ESC[0m\n\ESC[34m[info] \ESC[0mNo git version tags found, so assuming current version is v0.0.0\ESC[0m\n\ESC[34m[info] \ESC[0m** Running action: write the new config to the `bower.json` file and try to install its dependencies\ESC[0m\n\ESC[34m[info] \ESC[0mWriting the new Bower config to \"bower.json\"\ESC[0m\n\ESC[34m[info] \ESC[0mRunning `bower install` so `pulp publish` can read resolved versions from it\ESC[0m\n\ESC[31m[error] \ESC[0mA new bower.json has been generated. Please commit this and run `bump-version` again.\ESC[0m\n")

  To rerun use: --match "/BumpVersion/spago bump-version/end to end tests/Spago should use v0.0.0 as initial version/"

  test\SpagoSpec.hs:56:7:
  3) Spago, spago init, Spago should import config from psc-package
       expected: "{-\nWelcome to a Spago project!\nYou can edit this file as you like.\n-}\n{ name = \"aaa\"\n, dependencies = [ \"console\", \"effect\", \"prelude\", \"psci-support\" ]\n, packages = ./packages.dhall\n, sources = [ \"src/**/*.purs\", \"test/**/*.purs\" ]\n}\n"
        but got: "{-\n\nWelcome to a Spago project!\n\nYou can edit this file as you like.\n\n-}\n\n{ name = \"aaa\"\n, dependencies = [ \"console\", \"effect\", \"prelude\", \"psci-support\" ]\n, packages = ./packages.dhall\n, sources = [ \"src/**/*.purs\", \"test/**/*.purs\" ]\n}\n"

  To rerun use: --match "/Spago/spago init/Spago should import config from psc-package/"

  test\SpagoSpec.hs:63:7:
  4) Spago, spago init, Spago should not import dependencies that are not in the package-set
       expected: "{-\nWelcome to a Spago project!\nYou can edit this file as you like.\n-}\n{ name = \"aaa\"\n, dependencies = [ \"console\", \"effect\", \"psci-support\" ]\n, packages = ./packages.dhall\n, sources = [ \"src/**/*.purs\", \"test/**/*.purs\" ]\n}\n"
        but got: "{-\n\nWelcome to a Spago project!\n\nYou can edit this file as you like.\n\n-}\n\n{ name = \"aaa\"\n, dependencies = [ \"console\", \"effect\", \"psci-support\" ]\n, packages = ./packages.dhall\n, sources = [ \"src/**/*.purs\", \"test/**/*.purs\" ]\n}\n"

  To rerun use: --match "/Spago/spago init/Spago should not import dependencies that are not in the package-set/"

  test\SpagoSpec.hs:71:7:
  5) Spago, spago init, Spago should import configs from Bower
       expected: "{-\nWelcome to a Spago project!\nYou can edit this file as you like.\n-}\n{ name = \"simple-json\"\n, dependencies =\n  [ \"arrays\"\n  , \"assert\"\n  , \"console\"\n  , \"effect\"\n  , \"exceptions\"\n  , \"foreign\"\n  , \"foreign-object\"\n  , \"generics-rep\"\n  , \"globals\"\n  , \"nullable\"\n  , \"prelude\"\n  , \"psci-support\"\n  , \"record\"\n  , \"typelevel-prelude\"\n  , \"variant\"\n  ]\n, packages = ./packages.dhall\n, sources = [ \"src/**/*.purs\", \"test/**/*.purs\" ]\n}\n"
        but got: "{-\n\nWelcome to a Spago project!\n\nYou can edit this file as you like.\n\n-}\n\n{ name = \"simple-json\"\n, dependencies =\n  [ \"arrays\"\n  , \"assert\"\n  , \"console\"\n  , \"effect\"\n  , \"exceptions\"\n  , \"foreign\"\n  , \"foreign-object\"\n  , \"generics-rep\"\n  , \"globals\"\n  , \"nullable\"\n  , \"prelude\"\n  , \"psci-support\"\n  , \"record\"\n  , \"typelevel-prelude\"\n  , \"variant\"\n  ]\n, packages = ./packages.dhall\n, sources = [ \"src/**/*.purs\", \"test/**/*.purs\" ]\n}\n"

  To rerun use: --match "/Spago/spago init/Spago should import configs from Bower/"

  test\SpagoSpec.hs:116:7:
  6) Spago, spago install, Spago should be able to add dependencies
       expected: "{-\nWelcome to a Spago project!\nYou can edit this file as you like.\n-}\n{ name = \"aaa\"\n, dependencies =\n  [ \"console\", \"effect\", \"foreign\", \"prelude\", \"psci-support\", \"simple-json\" ]\n, packages = ./packages.dhall\n, sources = [ \"src/**/*.purs\", \"test/**/*.purs\" ]\n}\n"
        but got: "{-\n\nWelcome to a Spago project!\n\nYou can edit this file as you like.\n\n-}\n\n{ name = \"aaa\"\n, dependencies =\n  [ \"console\", \"effect\", \"foreign\", \"prelude\", \"psci-support\", \"simple-json\" ]\n, packages = ./packages.dhall\n, sources = [ \"src/**/*.purs\", \"test/**/*.purs\" ]\n}\n"

  To rerun use: --match "/Spago/spago install/Spago should be able to add dependencies/"

  test\SpagoSpec.hs:124:7:
  7) Spago, spago install, Spago should not add dependencies that are not in the package set
       expected: "{-\nWelcome to a Spago project!\nYou can edit this file as you like.\n-}\n{ name = \"aaa\"\n, dependencies = [ \"console\", \"effect\", \"prelude\", \"psci-support\" ]\n, packages = ./packages.dhall\n, sources = [ \"src/**/*.purs\", \"test/**/*.purs\" ]\n}\n"
        but got: "{-\n\nWelcome to a Spago project!\n\nYou can edit this file as you like.\n\n-}\n\n{ name = \"aaa\"\n, dependencies = [ \"console\", \"effect\", \"prelude\", \"psci-support\" ]\n, packages = ./packages.dhall\n, sources = [ \"src/**/*.purs\", \"test/**/*.purs\" ]\n}\n"

  To rerun use: --match "/Spago/spago install/Spago should not add dependencies that are not in the package set/"

Randomized with seed 30019396

Finished in 600.5443 seconds
90 examples, 7 failures

spago             > Test suite spec failed
Completed 14 action(s).
Test suite failure for package spago-0.14.0
    spec:  exited with: ExitFailure 1
Logs printed to console

@f-f
Copy link
Member Author

f-f commented Mar 26, 2020

@gibranrosa that's right, it doesn't look like the failures depend on these changes - ..however I wonder why they do happen 🤔

@f-f f-f changed the title Try fixing encoding problems by switching to the with-utf8 library Fix encoding problems: use with-utf8 library + a few other tricks Mar 29, 2020
@f-f f-f changed the title Fix encoding problems: use with-utf8 library + a few other tricks Fix encoding problems: use with-utf8 library and other tricks Mar 29, 2020
@f-f f-f changed the title Fix encoding problems: use with-utf8 library and other tricks Fix encoding issues: use with-utf8 library and other tricks Mar 29, 2020
@f-f
Copy link
Member Author

f-f commented Mar 29, 2020

I switched the Windows tests to use Japanese encoding, and they all pass now!
So it looks like we did it 🎉

I'll merge and cut a new release with the fix, thanks everyone for the great help 🙂

@f-f f-f merged commit 9a1429d into master Mar 29, 2020
@f-f f-f deleted the possibly-fix-encoding-problems branch March 29, 2020 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants