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

E.x on error value should access error detail record field #221

Closed
sanjiva opened this issue Jun 17, 2019 · 6 comments
Closed

E.x on error value should access error detail record field #221

sanjiva opened this issue Jun 17, 2019 · 6 comments
Assignees
Labels
enhancement Enhancement to language design lang Relates to the Ballerina language specification

Comments

@sanjiva
Copy link
Contributor

sanjiva commented Jun 17, 2019

Example:

type HttpError error <http-error”,
   record {
      string message;
      error cause?;
      map<anydata> otherStuff?;
   }
>;

error e0 = error ("something)"
HttpError e1 = error (message = "shit happened", cause = e0);

To access the message today we have to do this:

io:println ("Ooops: ", e1.details().message);

Can we allow:

io:println ("Ooops: ", e1.message);

I think the compiler can validate this correctly.

@jclark jclark changed the title convenient access to error detail fields Make E.x expression on error access error detail record Jun 17, 2019
@jclark jclark added enhancement Enhancement to language design lang Relates to the Ballerina language specification labels Jun 17, 2019
@jclark jclark added this to the 2019R4 milestone Jun 17, 2019
@jclark jclark self-assigned this Jun 17, 2019
@jclark
Copy link
Collaborator

jclark commented Jun 17, 2019

Yes, I think that would work fine. If we do this, we should also make ?. operator work also.

@jclark
Copy link
Collaborator

jclark commented Jun 18, 2019

This suggestion led me to a long and productive train of thought:

#169 (comment)

@jclark jclark changed the title Make E.x expression on error access error detail record E.x on error value should access error detail record field Jun 18, 2019
@jclark jclark modified the milestones: 2019R5, 2020R1 Dec 21, 2019
@jclark
Copy link
Collaborator

jclark commented Feb 18, 2020

There's a complication. Consider

json j = 3;
var v = j.x?.message;

json is laxly typed, so j.x is compile-time OK but evaluates to an error e. Now if we make the change suggested in this issue, e?.message on an error will be OK resulting in the message field of the detail record or nil.

So the semantic has to be more that E.x is desugared into E.detail().x when E is a subtype of error.

@jclark jclark modified the milestones: 2020R1, 2020R2 Feb 24, 2020
@jclark
Copy link
Collaborator

jclark commented Apr 8, 2020

This interacts with nominal typing #413. If the error reason string becomes a brand, and we introduce branded records, then access to the fields of the error detail record should become similar to access to the fields of a branded record.

@jclark jclark modified the milestones: 2020R3, 2020R2 Apr 24, 2020
@jclark
Copy link
Collaborator

jclark commented Apr 25, 2020

I think we should not do this:

@jclark
Copy link
Collaborator

jclark commented Apr 28, 2020

We decided not to do this.

@jclark jclark closed this as completed Apr 28, 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 lang Relates to the Ballerina language specification
Projects
None yet
Development

No branches or pull requests

2 participants