plfa / plfa.github.io

An introduction to programming language theory in Agda
https://plfa.github.io
Creative Commons Attribution 4.0 International
1.36k stars 307 forks source link

Build error: hGetContents: invalid argument #970

Closed OlingCat closed 7 months ago

OlingCat commented 7 months ago

Try to make build again and encountered the following error:

$ make build
Building PLFA...
cabal  v2-update
Downloading the latest package list from hackage.haskell.org
Package list of hackage.haskell.org has been updated.
The index-state is set to 2024-02-29T09:26:46Z.
To revert to previous state run:
    cabal v2-update 'hackage.haskell.org,2024-02-29T09:25:21Z'
cabal  v2-run builder -- build -j --lint --profile=_cache/reports/build.html --timing
Resolving dependencies...
Using Agda standard library version v1.7.2
Error when running Shake build system:
  at want, called at src\Development\Shake\Internal\Args.hs:83:67 in shake-0.19.8-2818591df20e946105545bdc96e1b31fe16dfbc8:Development.Shake.Internal.Args
* Depends on: build
  at need, called at tools\Buildfile.hs:245:9 in main:Main
* Depends on: _site/GettingStarted/index.html
  at need, called at shoggoth\Shoggoth\Metadata.hs:137:3 in shoggoth-0.1.0.0-cff87bafa44ea9e61bd795cf4f24696fdbb8ce4e:Shoggoth.Metadata
* Depends on: _cache/body_html/README.html
* Raised the exception:
README.md: hGetContents: invalid argument (cannot decode byte sequence starting from 147)

( Note:↑ This may be a different *.md file. )

make: *** [Makefile:33: build] Error 1
wenkokke commented 7 months ago

Have you tried clearing the cache?

OlingCat commented 7 months ago

Have you tried clearing the cache?

Aha! That's the point! Just make clobber and then build passed. Thank you!

OlingCat commented 7 months ago

Build passed on Arch in WSL, but still didn't work on Windows. This may appear on a non-English Windows system. I'll try to change my system language into English and try again.

OlingCat commented 7 months ago

Conclusion: If you are on a non-English Windows system, execute chcp 65001 in your cmd/PowerShell before make build.

wenkokke commented 7 months ago

Could we detect if we're on Windows with a non-English system language in the Makefile and run chcp 65001?

OlingCat commented 7 months ago

Could we detect if we're on Windows with a non-English system language in the Makefile and run chcp 65001?

I found a pwsh function called Get-WinSystemLocale | select -ExpandProperty Name, this may help.

Even thought I think it's OK to set chcp 65001 for all language versions of Windows including English (en-US), this basically tell the terminal to use UTF-8 encoding text, which is compatible with English.

But on Chinese (zh-CN) Windows system, the default terminal encoding is GBK, which is not compatible with UTF-8, so we should run chcp 65001 to change the standard I/O stream encoding into UTF-8.

wenkokke commented 7 months ago

Great! So it's just a matter of detecting Windows, I suppose, which, I believe, is easily done.

OlingCat commented 7 months ago

Great! So it's just a matter of detecting Windows, I suppose, which, I believe, is easily done.

I just wrote a makefile to do this. Feel free to add the following code to your makefile in the proper style:

# Check if on Windows
ifeq ($(OS),Windows_NT)
    CHCP := $(WINDIR)\System32\chcp.com
endif

.PHONY: build
build:

# Change console page code to 65001 (UTF-8).
ifdef CHCP
    $(CHCP) 65001
endif
wenkokke commented 7 months ago

The following would probably be fine:

.PHONY: build
build:
ifeq ($(OS),Windows_NT)
    # Change console page code to 65001 (UTF-8).
    $(WINDIR)\System32\chcp.com 65001
endif

Do you know if the absolute path to chcp is necessary?

OlingCat commented 7 months ago

Do you know if the absolute path to chcp is necessary?

I think it may not be necessary. Your way is better.