-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Avoid instanceof
which leads to runtime errors with deep npm dependencies
#47
Comments
There still seems to be a few occurrences of instance of around:
|
Confirming that this works. The approach is to override |
Reopening based on further investigation and how it interacts with Babel: |
dselman
added a commit
that referenced
this issue
Nov 22, 2021
Signed-off-by: Dan Selman <[email protected]>
jeromesimeon
pushed a commit
that referenced
this issue
Nov 22, 2021
Signed-off-by: Dan Selman <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The use of
instanceof
to check whether an object is of a class leads to unreliable check when importing Composer Concerto in projects with deep npm dependencies.Context
Composer Concerto uses
instanceof
checks e.g., here https://github.com/hyperledger/composer-concerto/blob/37189e52c4f52d13cbd862b38d36a64022976398/lib/serializer/resourcevalidator.js#L72 or here https://github.com/hyperledger/composer-concerto/blob/37189e52c4f52d13cbd862b38d36a64022976398/lib/serializer/jsonpopulator.js#L96Those can be unreliable since it checks whether this is the same object from the exact same package installed in a node.js project.
The reason it is unreliable is that it is difficult to enforce that the corresponding version of
composer-concerto
is installed exactly once in the./node_modules
directory throughnpm install
.This can lead to runtime errors when doing validation/serialization in some projects with deep npm dependencies.
Expected Behavior
A project should be able to import Composer Concerto 0.7.1 and PROJECT 0.X.X depending on e.g., Composer Concerto 0.7.0 without leading to runtime errors.
Actual Behavior
Currently a project has to ensure every dependency which import Composer Concerto have the exact same version, and that
npm install
leads to only one copy of that same version, which is difficult to guarantee (due to the waynpm install
works).Possible Fix
Several fixes are suggested in: https://stackoverflow.com/questions/41587865/using-instanceof-on-objects-created-with-constructors-from-deep-npm-dependenci
The recommended fix is to use an explicit method to check whether an object has the expected class. So instead of writing
thing instanceof RelationshipDeclaration
one would writeisRelationshipDeclaration(thing)
where:Steps to Reproduce
Existing issues
Context
Importing Composer Concerto in various parts of the Accord Project (Ergo, Cicero, Cicero template library, template studio, etc.).
Your Environment
The text was updated successfully, but these errors were encountered: