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

chore: remove __type and isa from shapes #1502

Merged
merged 4 commits into from Sep 9, 2020
Merged

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Sep 4, 2020

Issue #, if available:

Following PRs should be merged before this PR:

Description of changes:
remove __type and isa from shapes

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@trivikr trivikr marked this pull request as draft September 4, 2020 05:57
@codecov-commenter
Copy link

codecov-commenter commented Sep 4, 2020

Codecov Report

Merging #1502 into master will decrease coverage by 0.16%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1502      +/-   ##
==========================================
- Coverage   79.80%   79.63%   -0.17%     
==========================================
  Files         298      299       +1     
  Lines       11502    11634     +132     
  Branches     2475     2483       +8     
==========================================
+ Hits         9179     9265      +86     
- Misses       2323     2369      +46     
Impacted Files Coverage Δ
...l_tests/aws-json/commands/EmptyOperationCommand.ts 90.00% <0.00%> (-10.00%) ⬇️
...ts/aws-query/commands/NoInputAndNoOutputCommand.ts 90.00% <0.00%> (-10.00%) ⬇️
.../aws-restxml/commands/NoInputAndNoOutputCommand.ts 90.00% <0.00%> (-10.00%) ⬇️
...aws-restjson/commands/NoInputAndNoOutputCommand.ts 90.00% <0.00%> (-10.00%) ⬇️
protocol_tests/aws-ec2/commands/XmlBlobsCommand.ts 95.00% <0.00%> (-5.00%) ⬇️
protocol_tests/aws-ec2/commands/XmlEnumsCommand.ts 95.00% <0.00%> (-5.00%) ⬇️
protocol_tests/aws-ec2/commands/XmlListsCommand.ts 95.00% <0.00%> (-5.00%) ⬇️
...rotocol_tests/aws-query/commands/XmlMapsCommand.ts 95.00% <0.00%> (-5.00%) ⬇️
...otocol_tests/aws-query/commands/XmlBlobsCommand.ts 95.00% <0.00%> (-5.00%) ⬇️
...otocol_tests/aws-query/commands/XmlEnumsCommand.ts 95.00% <0.00%> (-5.00%) ⬇️
... and 115 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ead3816...e70c79f. Read the comment docs.

@trivikr trivikr marked this pull request as ready for review September 8, 2020 21:32
@AllanZhengYP
Copy link
Contributor

Can we keep the __type and isa() in exceptions? Without isa() the error handling experience would have a regress. For example, users cannot use type predicate when handling errors with special keys in their interface. Previously, users can:

import { SpecialException } from "client-foo";
try {
 ...
} catch (e) {
  if (SpecialException.isa(e)) {
   const key =  e.someSpecialKey // someSpecialKey is available in type
  }
}

@trivikr
Copy link
Member Author

trivikr commented Sep 8, 2020

Can we keep the __type and isa() in exceptions?

The __type is not required in Exceptions, as name property is populated with the same value.

Using instanceof is a better solution than using isa()
MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Handling_a_specific_error

@trivikr
Copy link
Member Author

trivikr commented Sep 8, 2020

Using instanceof is a better solution than using isa()

Actually, comparing err.name instead of instanceof is also used in JavaScript ecosystem as explained in https://javascript.info/custom-errors#extending-error

// ...
// instead of (err instanceof SyntaxError)
} else if (err.name == "SyntaxError") { // (*)
// ...

Although instanceof is future-proof, and it's better to have that supported.

@AllanZhengYP
Copy link
Contributor

Both instanceof and err.name work in this case. But instanceof will have better type support. If we are going with this path, let's add the support sooner than later: Generating all the error shapes in classes(or constructors) instead of structures.

@trivikr
Copy link
Member Author

trivikr commented Sep 9, 2020

Generating all the error shapes in classes(or constructors) instead of structures.

Created a feature request for it at #1506

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants