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

Render errors as JSON in http response #5545

Merged
merged 5 commits into from
Jan 15, 2024
Merged

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented Nov 20, 2023

Description

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. These may include:
    • golden tests
    • property tests
    • roundtrip tests
    • integration tests
      See Runnings tests for more details
  • Any changes are noted in the CHANGELOG.md for affected package
  • The version bounds in .cabal files are updated
  • CI passes. See note on CI. The following CI checks are required:
    • Code is linted with hlint. See .github/workflows/check-hlint.yml to get the hlint version
    • Code is formatted with stylish-haskell. See .github/workflows/stylish-haskell.yml to get the stylish-haskell version
    • Code builds on Linux, MacOS and Windows for ghc-8.10.7 and ghc-9.2.7
  • Self-reviewed the diff

Note on CI

If your PR is from a fork, the necessary CI jobs won't trigger automatically for security reasons.
You will need to get someone with write privileges. Please contact IOG node developers to do this
for you.

@newhoggy newhoggy changed the title Delete unused code Render errors as JSON in http response Nov 20, 2023
@newhoggy newhoggy requested a review from smelc December 9, 2023 09:21
@newhoggy newhoggy force-pushed the newhoggy/structured-errors branch 3 times, most recently from d52ca7a to ebd5dda Compare December 9, 2023 12:03
kind: ShelleyTxValidationError
tag: TxValidationErrorInCardanoMode
tag: TxCmdTxSubmitValidationError
tag: TxSubmitFail
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the response that will be returned. The golden file is yaml, but the response will be the JSON equivalent.

Copy link
Contributor

@Jimbo4350 Jimbo4350 Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit of yaml vs pretty JSON? My thinking is it's better to be close to the actual output.


newtype TxSubmitPort = TxSubmitPort Int

-- | The errors that the raw CBOR transaction parsing\/decoding functions can return.
--
newtype RawCborDecodeError = RawCborDecodeError [DecoderError]
deriving (Eq, Show)
deriving (Eq, Generic, Show)

instance Error RawCborDecodeError where
prettyError (RawCborDecodeError decodeErrors) = "RawCborDecodeError decode error: " <> pshow (fmap pshow decodeErrors)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this instance can be simplified a bit

Suggested change
prettyError (RawCborDecodeError decodeErrors) = "RawCborDecodeError decode error: " <> pshow (fmap pshow decodeErrors)
prettyError (RawCborDecodeError decodeErrors) = "RawCborDecodeError decode error:" <+> pshow decodeErrors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This instance wasn't added in the PR.

Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coupe of minor comments

@@ -50,34 +57,40 @@ data TxSubmitWebApiError
| TxSubmitBadTx !Text
| TxSubmitFail TxCmdError

newtype EnvSocketError = CliEnvVarLookup Text deriving (Eq, Show)
deriving instance Generic TxSubmitWebApiError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather we take the time to be explicit about ToJSON TxSubmitWebApiError. It gives us better control over deprecation handling or in general customizing the output to our liking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can certainly expand this into a manual ToJSON instance. Do you want the ToJSON instance to behave like the generic instance or something different?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a preference as long as it's explicit


data TxCmdError
= TxCmdSocketEnvError EnvSocketError
| TxCmdEraConsensusModeMismatch !AnyCardanoEra
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constructor is not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. Thanks!

kind: ShelleyTxValidationError
tag: TxValidationErrorInCardanoMode
tag: TxCmdTxSubmitValidationError
tag: TxSubmitFail
Copy link
Contributor

@Jimbo4350 Jimbo4350 Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit of yaml vs pretty JSON? My thinking is it's better to be close to the actual output.

@newhoggy
Copy link
Contributor Author

What's the benefit of yaml vs pretty JSON? My thinking is it's better to be close to the actual output.

I switch to use pretty JSON.

YAML would have some benefit if the JSON string contained newlines, but that might not happen in this case.

@newhoggy newhoggy added this pull request to the merge queue Dec 13, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Dec 13, 2023
@newhoggy newhoggy added this pull request to the merge queue Dec 20, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 20, 2023
@newhoggy newhoggy force-pushed the newhoggy/structured-errors branch 2 times, most recently from 1ec95fa to 62df968 Compare January 4, 2024 02:07
@newhoggy newhoggy force-pushed the newhoggy/structured-errors branch 2 times, most recently from 867fd60 to b070859 Compare January 12, 2024 12:45
@newhoggy newhoggy added this pull request to the merge queue Jan 12, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jan 12, 2024
@newhoggy newhoggy added this pull request to the merge queue Jan 13, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jan 13, 2024
@newhoggy newhoggy added this pull request to the merge queue Jan 13, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jan 13, 2024
@newhoggy newhoggy added this pull request to the merge queue Jan 14, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 14, 2024
@newhoggy newhoggy added this pull request to the merge queue Jan 14, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 14, 2024
@newhoggy newhoggy added this pull request to the merge queue Jan 14, 2024
@newhoggy newhoggy removed this pull request from the merge queue due to a manual request Jan 14, 2024
@newhoggy newhoggy added this pull request to the merge queue Jan 14, 2024
Merged via the queue into master with commit 54252c5 Jan 15, 2024
19 of 21 checks passed
@newhoggy newhoggy deleted the newhoggy/structured-errors branch January 15, 2024 00:27
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.

4 participants