-
Notifications
You must be signed in to change notification settings - Fork 282
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
style(examples): 2021-09-20 linter warnings batch 17 / 26; part 2 #2425
style(examples): 2021-09-20 linter warnings batch 17 / 26; part 2 #2425
Conversation
69aac58
to
1e98a5b
Compare
@adrianbatuto thankyou for the PR ! |
Thanks @jagpreetsinghsasan. I have made some updates to the pr. |
Suggested edit: diff --git a/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/model/converter/bamboo-harvest-converter.ts b/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/model/converter/bamboo-harvest-converter.ts
index 7aa858086..0b2981a63 100644
--- a/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/model/converter/bamboo-harvest-converter.ts
+++ b/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/model/converter/bamboo-harvest-converter.ts
@@ -1,4 +1,5 @@
import { BambooHarvest } from "../../generated/openapi/typescript-axios";
+import { RuntimeError } from 'run-time-error';
/**
* Responsible for converting model entities such as the `BambooHarvest` to and
@@ -22,9 +23,21 @@ export class BambooHarvestConverter {
* `BambooHarvest` model entity.
*/
public static ofSolidityStruct(arr: unknown[]): BambooHarvest {
+ const id = arr[BambooHarvestConverter.SOLIDITY_FIELD_ID];
+ if (typeof id !== "string") {
+ const errMsg = `Expected the value of arr[${BambooHarvestConverter.SOLIDITY_FIELD_ID}] to be a string`;
+ throw new RuntimeError(errMsg);
+ }
+
+ const location = arr[BambooHarvestConverter.SOLIDITY_FIELD_LOCATION];
+ if (typeof location !== "string") {
+ const errMsg = `Expected the value of arr[${BambooHarvestConverter.SOLIDITY_FIELD_LOCATION}] to be a string`;
+ throw new RuntimeError(errMsg);
+ }
+
return {
- id: arr[BambooHarvestConverter.SOLIDITY_FIELD_ID] as string,
- location: arr[BambooHarvestConverter.SOLIDITY_FIELD_LOCATION] as string,
+ id,
+ location,
startedAt: arr[
BambooHarvestConverter.SOLIDITY_FIELD_STARTED_AT
] as string,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my suggestion and make sure to apply the same logic for the rest of the fields e.g. these below:
startedAt: arr[
BambooHarvestConverter.SOLIDITY_FIELD_STARTED_AT
] as string,
endedAt: arr[BambooHarvestConverter.SOLIDITY_FIELD_ENDED_AT] as string,
harvester: arr[BambooHarvestConverter.SOLIDITY_FIELD_HARVESTER] as string,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adrianbatuto I added a couple more comments here, please see above.
...upply-chain-business-logic-plugin/src/main/typescript/model/converter/bookshelf-converter.ts
Outdated
Show resolved
Hide resolved
...ly-chain-frontend/src/app/bamboo-harvest/bamboo-harvest-detail/bamboo-harvest-detail.page.ts
Outdated
Show resolved
Hide resolved
35e19c6
to
756c56d
Compare
...ly-chain-frontend/src/app/bamboo-harvest/bamboo-harvest-detail/bamboo-harvest-detail.page.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adrianbatuto See my comments above please
1. Added a user-defined type guard to check for `BambooHarvest` types on the front-end. 2. Additional runtime type checks during data type conversion so that if we get invalid input it speaks up against it specifically instead of using `any` types and generic crashes. Fixes hyperledger-cacti#2092 Co-authored-by: Peter Somogyvari <peter.somogyvari@accenture.com> Signed-off-by: adrianbatuto <adrian.batuto@accenture.com> Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
756c56d
to
acdcec6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adrianbatuto nvm, I pushed some fixes just now so that we can get this over the line ASAP. Apart from my comments above the other thing that I changed is that I moved the user-defined type guard to it's own code-file and exported it so that it can be re-used elsewhere.
BambooHarvest
typeson the front-end.
if we get invalid input it speaks up against it specifically instead of
using
any
types and generic crashes.Fixes #2092
Co-authored-by: Peter Somogyvari peter.somogyvari@accenture.com
Signed-off-by: adrianbatuto adrian.batuto@accenture.com
Signed-off-by: Peter Somogyvari peter.somogyvari@accenture.com