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

Revised error design #509

Closed
jclark opened this issue May 1, 2020 · 4 comments
Closed

Revised error design #509

jclark opened this issue May 1, 2020 · 4 comments
Assignees
Labels
enhancement Enhancement to language design implementation/done Implementation Done incompatible Resolving issue may not be backwards compatible lang Relates to the Ballerina language specification status/inprogress Fixes are in the process of being added

Comments

@jclark
Copy link
Collaborator

jclark commented May 1, 2020

This issue covers a new error design that deals with issues #459, #393, #501. It takes advantage of the distinct type feature from #413.

  • errors are categorized using type-ids, which are part of the distinct type feature rather than the error reason string
  • the error reason string is removed
  • the error type descriptor has a single type parameter, which specifies the detail record
  • message and cause move from the detail record into the error itself
    • the type is string and error? respectively
    • the message is required
    • the cause defaults to () if not specified
    • they are specified by positional arguments to the error constructor
    • lang.error provides message and cause functions to access them
  • the required type of detail record is map<anydata|readonly> (with no predefined fields)
  • the positional parameters of error constructors specify the message and cause
  • if the error constructor uses a type that does not specify a detail record type with individual fields, then named arguments can be used to specify arbitrary fields
  • if the error constructor uses a type that does specify a detail record type with individual fields, then the named arguments can only be used to specify those fields; other fields must be specified with ... and a mapping constructor (not sure if this functionality is really necessary)

Intersection types #508 allow a type descriptor to describe both the type-ids and the detail record.

@jclark
Copy link
Collaborator Author

jclark commented May 1, 2020

Nominal types design also includes the following.

An error type error<R> means that the detail record must belong to the type

    readonly & record {| *R; (anydata|readonly)...; |}

In a match-statement, a error-match-pattern with a user-defined error type should match only if the shape of the value belongs to type.

@jclark
Copy link
Collaborator Author

jclark commented May 1, 2020

We also need to fix toString for error as described in #459 (comment)

@jclark jclark self-assigned this May 1, 2020
@jclark jclark added enhancement Enhancement to language design incompatible Resolving issue may not be backwards compatible lang Relates to the Ballerina language specification labels May 1, 2020
@jclark jclark added this to the 2020R2 milestone May 1, 2020
@jclark jclark added the status/inprogress Fixes are in the process of being added label May 1, 2020
@jclark jclark mentioned this issue May 1, 2020
jclark added a commit that referenced this issue May 1, 2020
Deals with most of #509.
@jclark
Copy link
Collaborator Author

jclark commented May 1, 2020

Still to do:

  • error<T> means detail record belongs to readonly & T
  • explain when type descriptor for subtype of error can be used in functional constructor: must be definite and can be intersection
  • toString on error should include primary type ids
  • restriction on when individual field names can be used in error constructor
  • rest argument in error constructor
  • avoid poor interactions between intersection and exclusive record types

Last two are about how openness should work for the detail record; not yet 100% confident we have this right.

@jclark
Copy link
Collaborator Author

jclark commented Jun 18, 2020

I have moved the remaining parts of this into #550.

@jclark jclark closed this as completed Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to language design implementation/done Implementation Done incompatible Resolving issue may not be backwards compatible lang Relates to the Ballerina language specification status/inprogress Fixes are in the process of being added
Projects
None yet
Development

No branches or pull requests

2 participants