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

Use Result type and throw fewer errors in Client and Core #1277

Merged
merged 29 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e8fa6e7
Replaced thrown exceptions with Result types in core-js
krisbitney Sep 21, 2022
feca068
Replaced thrown exceptions with Result types in wasm-js
krisbitney Sep 21, 2022
9472c7c
Replaced thrown exceptions with Result types in uri resolvers and mor…
krisbitney Sep 21, 2022
3025b88
Replaced thrown exceptions with Result types in client; tests failing
krisbitney Sep 24, 2022
2343be3
Updated schema-bind with Result type
krisbitney Sep 24, 2022
42c8a37
Merge remote-tracking branch 'origin/origin-dev' into use-result-clie…
krisbitney Sep 24, 2022
ffac945
Updated cli with Result type
krisbitney Sep 24, 2022
f5517ba
monorepo building with Result type (untested)
krisbitney Sep 25, 2022
54f8a96
client tests passing
krisbitney Sep 25, 2022
4537d0e
plugin tests passing
krisbitney Sep 26, 2022
095b9c7
cli tests passing
krisbitney Sep 26, 2022
86caf5a
Merge remote-tracking branch 'origin/origin-dev' into use-result-clie…
krisbitney Sep 26, 2022
ca10282
fix for Result type in some Ethereum plugin tests
krisbitney Sep 26, 2022
fa6c52d
fix: link schema packages to dep cli
dOrgJelli Sep 26, 2022
c20c6de
chore: use InvokeResult instead of Result
dOrgJelli Sep 26, 2022
84d029e
chore: use InvokeResult
dOrgJelli Sep 26, 2022
fde86ec
chore: fix build
dOrgJelli Sep 26, 2022
657b2da
merge origin-dev
dOrgJelli Sep 26, 2022
6ab5736
chore: lint fix
dOrgJelli Sep 26, 2022
ae28dc1
chore: fix plugin codegen
dOrgJelli Sep 26, 2022
4ef83b3
refactored use of result in client, made loadWrapper public
nerfZael Sep 27, 2022
18a2e4f
using result for wrap packages
nerfZael Sep 27, 2022
bdbcba5
removed initWrapper
nerfZael Sep 27, 2022
a72d200
result fixes
nerfZael Sep 27, 2022
5bff6c2
using InvokeResult instead of Result
nerfZael Sep 27, 2022
fb618da
using InvokeResult instead of Result
nerfZael Sep 27, 2022
303ea6b
passing options to createWrapper
nerfZael Sep 27, 2022
f0be41e
chore: remove needless InvokeResult
dOrgJelli Sep 27, 2022
af0d730
Merge pull request #1285 from polywrap/nerfzael-result-error-handling…
dOrgJelli Sep 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"clean": "npx rimraf ./**/node_modules ./**/yarn.lock ./**/build ./**/coverage ./**/.polywrap",
"dependencies:install": "cd dependencies && yarn",
"preinstall": "yarn dependencies:install",
"build": "yarn build:core && yarn build:interfaces && yarn build:plugins && yarn build:resolver:plugins && yarn build:config && yarn build:client && yarn build:test-env && yarn build:cli",
"build": "yarn build:core && yarn link:schema && yarn build:interfaces && yarn build:plugins && yarn build:resolver:plugins && yarn build:config && yarn build:client && yarn build:test-env && yarn build:cli",
"build:core": "lerna run build --no-private --ignore @polywrap/*-plugin-js --ignore @polywrap/client-config-builder-js --ignore polywrap --ignore @polywrap/client-js --ignore @polywrap/react --ignore @polywrap/test-env-js --ignore @polywrap/*-interface",
"build:interfaces": "lerna run build --scope @polywrap/*-interface",
"build:plugins": "lerna run build --scope @polywrap/*-plugin-js --ignore @polywrap/*-resolver-plugin-js",
Expand All @@ -38,9 +38,10 @@
"link:manifests": "yarn link:manifests:polywrap && yarn link:manifests:wrap",
"link:manifests:polywrap": "cd packages/js/manifests/polywrap && (yarn unlink || true) && yarn link && cd ../../../../dependencies && yarn link @polywrap/polywrap-manifest-types-js && cd ../",
"link:manifests:wrap": "cd packages/js/manifests/wrap && (yarn unlink || true) && yarn link && cd ../../../../dependencies && yarn link @polywrap/wrap-manifest-types-js && cd ../",
"link:schema": "yarn link:schema:parse && yarn link:schema:compose",
"link:schema": "yarn link:schema:parse && yarn link:schema:compose && yarn link:schema:bind",
"link:schema:parse": "cd packages/schema/parse && (yarn unlink || true) && yarn link && cd ../../../dependencies && yarn link @polywrap/schema-parse && cd ../",
"link:schema:compose": "cd packages/schema/compose && (yarn unlink || true) && yarn link && cd ../../../dependencies && yarn link @polywrap/schema-compose && cd ../",
"link:schema:bind": "cd packages/schema/bind && (yarn unlink || true) && yarn link && cd ../../../dependencies && yarn link @polywrap/schema-bind && cd ../",
"lint": "lerna run lint",
"lint:fix": "lerna run lint -- --fix",
"lint:ci": "yarn lint",
Expand Down
11 changes: 5 additions & 6 deletions packages/cli/src/lib/SchemaComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,12 @@ export class SchemaComposer {
}
}

try {
const manifest = await this._client.getManifest(new Uri(uri));
return manifest.abi;
} catch (e) {
gluegun.print.error(e);
throw e;
const manifest = await this._client.getManifest(new Uri(uri));
if (!manifest.ok) {
gluegun.print.error(manifest.error);
throw manifest.error;
}
return manifest.value.abi;
}

private async _loadGraphqlAbi(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable @typescript-eslint/no-var-requires */
import { Deployer } from "../../../deploy/deployer";
import { Deployer } from "../../../deploy";

import { Wallet } from "@ethersproject/wallet";
import { JsonRpcProvider } from "@ethersproject/providers";
Expand Down Expand Up @@ -76,7 +76,7 @@ class ENSRecursiveNameRegisterPublisher implements Deployer {
],
});

const { data: signerAddress } = await client.invoke<string>({
const signerAddress = await client.invoke<string>({
method: "getSignerAddress",
uri: ethereumPluginUri,
args: {
Expand All @@ -86,40 +86,38 @@ class ENSRecursiveNameRegisterPublisher implements Deployer {
},
});

if (!signerAddress) {
if (!signerAddress.ok) {
throw new Error("Could not get signer");
}

const { data: registerData, error } = await client.invoke<{ hash: string }>(
{
method: "registerDomainAndSubdomainsRecursively",
uri: ensWrapperUri,
args: {
domain: ensDomain,
owner: signerAddress,
resolverAddress: config.ensResolverAddress,
ttl: "0",
registrarAddress: config.ensRegistrarAddress,
registryAddress: config.ensRegistryAddress,
connection: {
networkNameOrChainId: network,
},
const registerData = await client.invoke<{ hash: string }>({
method: "registerDomainAndSubdomainsRecursively",
uri: ensWrapperUri,
args: {
domain: ensDomain,
owner: signerAddress.value,
resolverAddress: config.ensResolverAddress,
ttl: "0",
registrarAddress: config.ensRegistrarAddress,
registryAddress: config.ensRegistryAddress,
connection: {
networkNameOrChainId: network,
},
}
);
},
});

if (!registerData) {
if (!registerData.ok) {
throw new Error(
`Could not register domain '${ensDomain}'` +
(error ? `\nError: ${error.message}` : "")
(registerData.error ? `\nError: ${registerData.error.message}` : "")
);
}

await client.invoke({
method: "awaitTransaction",
uri: ethereumPluginUri,
args: {
txHash: registerData.hash,
txHash: registerData.value.hash,
confirmations: 1,
timeout: 15000,
connection: {
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/src/lib/defaults/deploy-modules/ens/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable @typescript-eslint/no-var-requires */
import { Deployer } from "../../../deploy/deployer";
import { Deployer } from "../../../deploy";

import { Wallet } from "@ethersproject/wallet";
import { JsonRpcProvider } from "@ethersproject/providers";
Expand Down Expand Up @@ -77,7 +77,7 @@ class ENSPublisher implements Deployer {
],
});

const { data: resolver } = await client.invoke<string>({
const resolver = await client.invoke<string>({
method: "getResolver",
uri: ensWrapperUri,
args: {
Expand All @@ -89,38 +89,38 @@ class ENSPublisher implements Deployer {
},
});

if (!resolver) {
if (!resolver.ok) {
throw new Error(`Could not get resolver for '${config.domainName}'`);
}

if (resolver === "0x0000000000000000000000000000000000000000") {
if (resolver.value === "0x0000000000000000000000000000000000000000") {
throw new Error(`Resolver not set for '${config.domainName}'`);
}

const hash = "0x" + contentHash.fromIpfs(cid);

const { data: setContenthashData } = await client.invoke<{ hash: string }>({
const setContenthashData = await client.invoke<{ hash: string }>({
method: "setContentHash",
uri: ensWrapperUri,
args: {
domain: config.domainName,
cid: hash,
resolverAddress: resolver,
resolverAddress: resolver.value,
connection: {
networkNameOrChainId: network,
},
},
});

if (!setContenthashData) {
if (!setContenthashData.ok) {
throw new Error(`Could not set contentHash for '${config.domainName}'`);
}

await client.invoke({
method: "awaitTransaction",
uri: ethereumPluginUri,
args: {
txHash: setContenthashData.hash,
txHash: setContenthashData.value.hash,
confirmations: 1,
timeout: 15000,
connection: {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/lib/workflow/JobRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ export class JobRunner {
args: args,
});

if (invokeResult.error) {
return { ...invokeResult, status: JobStatus.FAILED };
if (!invokeResult.ok) {
return { error: invokeResult.error, status: JobStatus.FAILED };
} else {
return { ...invokeResult, status: JobStatus.SUCCEED };
return { data: invokeResult.value, status: JobStatus.SUCCEED };
}
}

Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/lib/workflow/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClientConfig, InvokeResult, Uri } from "@polywrap/core-js";
import { ClientConfig, Uri } from "@polywrap/core-js";

export interface Step {
uri: string | Uri;
Expand All @@ -15,7 +15,9 @@ export enum JobStatus {
SKIPPED = "SKIPPED",
}

export interface JobResult<TData = unknown> extends InvokeResult<TData> {
export interface JobResult<TData = unknown> {
data?: TData;
error?: Error;
status: JobStatus;
}

Expand Down
Loading