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

Allow error constructors to use named error type #223

Closed
jclark opened this issue Jun 18, 2019 · 4 comments · Fixed by ballerina-platform/ballerina-lang#16244
Closed

Allow error constructors to use named error type #223

jclark opened this issue Jun 18, 2019 · 4 comments · Fixed by ballerina-platform/ballerina-lang#16244
Assignees
Labels
Area/Lang Relates to the Ballerina language specification status/pending Design is agreed and waiting to be added Type/Improvement Enhancement to language design
Milestone

Comments

@jclark
Copy link
Collaborator

jclark commented Jun 18, 2019

This is the intermediate step between #67 and #2.

The main point is that if you specify the error detail string in the error type, you should not need to repeat it in the error constructor.

@jclark jclark added Type/Improvement Enhancement to language design Area/Lang Relates to the Ballerina language specification labels Jun 18, 2019
@jclark jclark added this to the 2019R2 milestone Jun 18, 2019
@jclark jclark self-assigned this Jun 18, 2019
@jclark
Copy link
Collaborator Author

jclark commented Jun 18, 2019

With this there are two kind of error constructor:

  1. the kind we have now, using error
  2. a new kind, which uses a user-defined type name referring to an error type instead of error

There are potentially three policies rules are regards the error reason argument: required, prohibited, optional. I believe our plan was to make it optional in both cases, but I think this is potentially confusing since it would have what is in effect an optional positional parameter, before a potentially required named parameter. So I would instead suggest a less flexible rule: make the error reason string required in the first case, and prohibited in the second case. This would mean that you can use the second kind only when the error type has a singleton error reason parameter.

@jclark jclark added the status/discuss Needs discussion outside github comments label Jun 18, 2019
@jclark jclark changed the title Allow error constructor expression to use named error type Allow error constructors to use named error type Jun 19, 2019
@jclark
Copy link
Collaborator Author

jclark commented Jun 19, 2019

Note this needs to work in binding patterns as well as expressions. The obvious semantics is that it matches if it belongs to the type. That raises to a point about the semantics of match #152 . We could separate this into a separate issue to do later.

@sanjiva
Copy link
Contributor

sanjiva commented Jun 19, 2019

I agree the current model is lacking clarity and simplicity.

+1 for a model where we say if you use the error() constructor you MUST give the reason string and that you CANNOT give it if use a particular type name as the constructor.

My only problem is that this further encroaches into establishing this as the way w.r.t. #2. I'm not happy about that :) but not sure what we can do right now (I will comment on that issue).

@sanjiva
Copy link
Contributor

sanjiva commented Jun 19, 2019

And I like the further restriction that the second kind is usable only when you have a singleton reason for that type. IMO we should encourage that - other than for binding patterns, I don't see unions of reasons being a good way to design errors.

@jclark jclark added status/pending Design is agreed and waiting to be added and removed status/discuss Needs discussion outside github comments labels Jun 20, 2019
jclark added a commit that referenced this issue Jun 24, 2019
Since these are defined by type definitions. Preparaton for #223.
@jclark jclark closed this as completed in 4f46d8c Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Lang Relates to the Ballerina language specification status/pending Design is agreed and waiting to be added Type/Improvement Enhancement to language design
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants