Skip to content

Commit

Permalink
Merge pull request #346 from near/fix-contract-method-conflicting
Browse files Browse the repository at this point in the history
Error and stop build a contract that has method name confliction
  • Loading branch information
ailisp authored Feb 24, 2023
2 parents 09ebf81 + e6ff90a commit 4b7fc3c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/near-sdk-js/lib/cli/cli.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/near-sdk-js/lib/cli/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/near-sdk-js/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ async function createMethodsHeaderFile(rollupTarget: string, verbose = false) {

const mod = await import(`${PROJECT_DIR}/${rollupTarget}`);
const exportNames = Object.keys(mod);
if (exportNames.includes('panic')) {
signal.error(
"'panic' is a reserved word, please use another name for contract method"
);
process.exit(1);
}
const methods = exportNames.reduce(
(result, key) => `${result}DEFINE_NEAR_METHOD(${key})\n`,
""
Expand Down
5 changes: 5 additions & 0 deletions packages/near-sdk-js/src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export async function executeCommand(
}
if (code != 0) {
signale.error(`Command failed: ${command}`);

const failDueToNameConflict = stderr.match(/conflicting types for '([a-zA-Z0-9_]+)'/);
if (failDueToNameConflict.length > 1) {
signale.error(`'${failDueToNameConflict[1]}' is a reserved word, please use another name for contract method"`);
}
}
if (stderr && verbose) {
signale.error(`Command stderr: ${stderr}`);
Expand Down

0 comments on commit 4b7fc3c

Please sign in to comment.