question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Named Record Types

See original GitHub issue

I work with a lot of objects, it’d be helpful to tag them with a name. It’d make for more terse signatures.

I still think we should show the complete interface if a type error occurs though. But when rendering the signature, it’d be preferable to just use the name, I’m finding type errors nearly always wrap the terminal/repl because I’m working with large records.

Then the ^^^^ don’t line up with the particular argument, so its not immediately obvious what is causing it to fail.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
davidchamberscommented, Apr 28, 2017

Good idea.

An idea that just occurred to me is to have the representation span multiply lines:

{
  bar :: Array String
  baz :: {
    quux :: Integer
            ^^^^^^^
               1
  }
  foo :: Boolean
}

As opposed to:

{ bar :: Array String, baz :: { quux :: Integer }, foo :: Boolean }
                                        ^^^^^^^
                                           1

We could use the name of the record type in the signature, then expand the type in the description below and underline the invalid portion.

1reaction
JAForbescommented, Jul 17, 2017

Some new thoughts:

I’m using this to validate API responses and there are a lot of fields, sometimes its hard to see what is wrong with a value when there are 50 keys with various levels of nesting.

It’s not that useful to render the complete type for large objects (say keys > 5, or levels of nesting greater than 2). It’d be a lot more useful to me to list the paths and types that were invalid, with the expected type and the actual value. Particularly when there are multiple validation issues.

TypeError ... yada

1. Value -123 at path: a.b.c.d is not a member of PositiveNumber
2. Value [1,2,3] at path: a.b.c.e is not a member of List String

It could also be handy to show the values in context, with the valid values filtered out.

TypeError Provided value did not satisfy custom RecordType API Response

The provided value did not satisfy the following Type constraints:

Preview:

  { a: 
    { b: 
      { c: 
         { d: -123, e: [1,2,3] }, ... 
       }, ... 
     }, ... 
  } 

1. Value -123 at path: a.b.c.d is not a member of PositiveNumber
2. Value [1,2,3] at path: a.b.c.e is not a member of List String

It’d be great too if validate, or something similar could provide this metadata as an object of the form: { preview :: String, failures:: List { value:: Any, path: List String, type: Type } }

That way libraries like sum-type (and hopefully others) could build domain specific error messages without recreating a lot of what sanctuary-def already does very well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DNS Record Types Cheat Sheet - Constellix
DNS Record Types · A Record (address)‍ · AAAA Record (quad A) · CNAME Record (Canonical Name) · ANAME Record · SOA Record...
Read more >
List of DNS record types - Wikipedia
This list of DNS record types is an overview of resource records (RRs) permissible in zone ... OpenPGP public key record, A DNS-based...
Read more >
DNS Record Types: Defined and Explained - Site24x7
DNS record types · 1. A record · 2. AAAA record · 3. CNAME record · 4. NS record · 5. MX record....
Read more >
Know the eight most common DNS records - BlueCat Networks
A and AAAA DNS records. Firstly, address (A) records are the most common record type by far. In brief, A records map domain...
Read more >
DNS Record Types Explained {Complete List} | phoenixNAP KB
A (address) records are one of the most basic and commonly used DNS record types. They translate domain names and store them as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found