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

Quieten show output for API types. #2762

Merged
merged 4 commits into from
Jul 16, 2021

Conversation

jonathanknowles
Copy link
Contributor

@jonathanknowles jonathanknowles commented Jul 15, 2021

Issue Number

None. (Produced while debugging test failures for #2741)

Overview

Integration test failures occasionally produce very verbose output, similar to the
following (an extract from a multi-page error):

, derivationPath = ApiT
    { getApiT = DerivationIndex
        { getDerivationIndex = 2147485500 }
    } :|
    [ ApiT
        { getApiT = DerivationIndex
            { getDerivationIndex = 2147485463 }
        }
    , ApiT
        { getApiT = DerivationIndex
            { getDerivationIndex = 2147483648 }
        }
    , ApiT
        { getApiT = DerivationIndex
            { getDerivationIndex = 0 }
        }
    , ApiT
        { getApiT = DerivationIndex
            { getDerivationIndex = 4 }
        }
    ]
, amount = Quantity
    { getQuantity = 100000000000 }
, assets = ApiT
    { getApiT = TokenMap
        ( fromList [] )
    }

Most of the above output is boilerplate: the getApiT and getDerivationIndex deconstructor field names are not necessary to understand the output, as each of these types is just a wrapper type with exactly one field.

We can remove this boilerplate by deriving our Show instances for newtypes via Quiet, which produces output similar to the following:

, derivationPath =
    ApiT (DerivationIndex 2147485500) :|
    [ ApiT (DerivationIndex 2147485463)
    , ApiT (DerivationIndex 2147483648)
    , ApiT (DerivationIndex 0)
    , ApiT (DerivationIndex 4)
    ]
, amount = Quantity 100000000000
, assets = ApiT (TokenMap (fromList []))

Real log output, demonstrating the difference in verbosity:

@jonathanknowles jonathanknowles changed the title Quieten Show instances for API types. Quieten show output for API types. Jul 15, 2021
Deriving a `Show` instance for newtype `T` via `Quiet T` allows the
deconstructor function for `T` to be omitted in the output of `show`.

With stock deriving, we often obtain very verbose output, similar to the
following:

```hs
derivationPath = ApiT
    { getApiT = DerivationIndex
        { getDerivationIndex = 2147485500 }
    } :|
    [ ApiT
        { getApiT = DerivationIndex
            { getDerivationIndex = 2147485463 }
        }
    , ApiT
        { getApiT = DerivationIndex
            { getDerivationIndex = 2147483648 }
        }
    , ApiT
        { getApiT = DerivationIndex
            { getDerivationIndex = 0 }
        }
    , ApiT
        { getApiT = DerivationIndex
            { getDerivationIndex = 4 }
        }
    ]
```

This occasionally causes integration test error output to be extremely verbose.

But when deriving via `Quiet`, the above output becomes:

```hs
derivationPath =
    ApiT (DerivationIndex 2147485500) :|
    [ ApiT (DerivationIndex 2147485463)
    , ApiT (DerivationIndex 2147483648)
    , ApiT (DerivationIndex 0)
    , ApiT (DerivationIndex 4)
    ]
```
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/quieten-api-newtype-show-instances branch from e768de4 to 1e85bd1 Compare July 15, 2021 04:16
These types are widely used in API types, so it makes sense to quieten
the output of `show` for these types too.

Before:

```hs
amount = Quantity { getQuantity = 100000000000 }
```

After:

```hs
amount = Quantity 100000000000
```
@jonathanknowles jonathanknowles self-assigned this Jul 15, 2021
Copy link
Member

@Anviking Anviking left a comment

Choose a reason for hiding this comment

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

Yay!

This type often appear in API types, and consequently in integration
test failures, so it makes sense to make the output of `show` less verbose.
@rvl
Copy link
Contributor

rvl commented Jul 16, 2021

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jul 16, 2021

Build succeeded:

@iohk-bors iohk-bors bot merged commit 53d6681 into master Jul 16, 2021
@iohk-bors iohk-bors bot deleted the jonathanknowles/quieten-api-newtype-show-instances branch July 16, 2021 07:11
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.

3 participants