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

Print aeson decoding error when metadata decoding fails #1113

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

mpickering
Copy link
Contributor

Previously the reported error is misleading

[ Info  ] downloading: https://ghc.gitlab.haskell.org/ghcup-metadata/ghcup-nightlies-0.0.7.yaml as file /Users/bchinn/.ghcup/cache/ghcup-nightlies-0.0.7.yaml
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  606k  100  606k    0     0   964k      0 --:--:-- --:--:-- --:--:--  963k
[ Error ] [GHCup-00160] JSON decoding failed with: Aeson exception:
[ ...   ] Error in $: key "ghc" not found
[ ...   ] Consider removing /Users/bchinn/.ghcup/cache/ghcup-nightlies-0.0.7.yaml manually.

because this is the error when trying to decode the metadata as a stack format.

The actual error is much better:

[ Debug ] Identified Platform as: Linux UnknownLinux, 24.05
[ Debug ] using local file: /home/matt/ghcup-hs/ghcup-nightlies-0.0.7.yaml
[ Debug ] Decoding yaml at: /home/matt/ghcup-hs/ghcup-nightlies-0.0.7.yaml
[ Debug ] Couldn't decode /home/matt/ghcup-hs/ghcup-nightlies-0.0.7.yaml as GHCupInfo, trying as SetupInfo: Aeson exception:
[ ...   ] Error in $.ghcupDownloads.GHC['9.11.20240719'].viArch['A_32']['Linux_Debian']['unknown versioning']: Failure in (Maybe VersionRange) (FromJSONKey)1:16:
[ ...   ]   |
[ ...   ] 1 | unknown versioning
[ ...   ]   |                ^
[ ...   ] unexpected 'v'
[ ...   ] expecting end of input or white space
[ ...   ]
[ ...   ] Consider removing /home/matt/ghcup-hs/ghcup-nightlies-0.0.7.yaml manually.
[ Debug ] Decoding yaml at: /home/matt/ghcup-hs/ghcup-nightlies-0.0.7.yaml
[ Error ] [GHCup-00160] JSON decoding failed with: Aeson exception:
[ ...   ] Error in $: key "ghc" not found
[ ...   ] Consider removing /home/matt/ghcup-hs/ghcup-nightlies-0.0.7.yaml manually.

Perhaps the fallback mechanism is a bit confusing and it would be better to have different command line options for ghcup/stack metadata. The bad error will still be reported to a user if they encounter malformed metadata.

Previously the reported error is misleading

```
[ Info  ] downloading: https://ghc.gitlab.haskell.org/ghcup-metadata/ghcup-nightlies-0.0.7.yaml as file /Users/bchinn/.ghcup/cache/ghcup-nightlies-0.0.7.yaml
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  606k  100  606k    0     0   964k      0 --:--:-- --:--:-- --:--:--  963k
[ Error ] [GHCup-00160] JSON decoding failed with: Aeson exception:
[ ...   ] Error in $: key "ghc" not found
[ ...   ] Consider removing /Users/bchinn/.ghcup/cache/ghcup-nightlies-0.0.7.yaml manually.
```

because this is the error when trying to decode the metadata as a stack
format.

The actual error is much better:

```
[ Debug ] Identified Platform as: Linux UnknownLinux, 24.05
[ Debug ] using local file: /home/matt/ghcup-hs/ghcup-nightlies-0.0.7.yaml
[ Debug ] Decoding yaml at: /home/matt/ghcup-hs/ghcup-nightlies-0.0.7.yaml
[ Debug ] Couldn't decode /home/matt/ghcup-hs/ghcup-nightlies-0.0.7.yaml as GHCupInfo, trying as SetupInfo: Aeson exception:
[ ...   ] Error in $.ghcupDownloads.GHC['9.11.20240719'].viArch['A_32']['Linux_Debian']['unknown versioning']: Failure in (Maybe VersionRange) (FromJSONKey)1:16:
[ ...   ]   |
[ ...   ] 1 | unknown versioning
[ ...   ]   |                ^
[ ...   ] unexpected 'v'
[ ...   ] expecting end of input or white space
[ ...   ]
[ ...   ] Consider removing /home/matt/ghcup-hs/ghcup-nightlies-0.0.7.yaml manually.
[ Debug ] Decoding yaml at: /home/matt/ghcup-hs/ghcup-nightlies-0.0.7.yaml
[ Error ] [GHCup-00160] JSON decoding failed with: Aeson exception:
[ ...   ] Error in $: key "ghc" not found
[ ...   ] Consider removing /home/matt/ghcup-hs/ghcup-nightlies-0.0.7.yaml manually.
```

Perhaps the fallback mechanism is a bit confusing and it would be better
to have different command line options for ghcup/stack metadata. The bad
error will still be reported to a user if they encounter malformed
metadata.
@hasufell
Copy link
Member

Perhaps the fallback mechanism is a bit confusing and it would be better to have different command line options for ghcup/stack metadata.

I decided against that. You can combine stack metadata with GHCup prereleases metadata.

I don't see how that would work well with cli switches.

@hasufell
Copy link
Member

Indeed it's bad ergonomics that the primary error is the stack decoding. The aeson error reporting is awful in general.

I'm open to more radical changes here, such as collecting the errors of all tried alternatives (at least "top-level").

I'm thinking there should be a combinator for this.

@mpickering
Copy link
Contributor Author

Anything blocking this patch being merged?

@hasufell hasufell merged commit e38c41b into haskell:master Sep 24, 2024
46 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants