Skip to content

Commit 4b7fc3c

Browse files
authored
Merge pull request #346 from near/fix-contract-method-conflicting
Error and stop build a contract that has method name confliction
2 parents 09ebf81 + e6ff90a commit 4b7fc3c

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

Diff for: packages/near-sdk-js/lib/cli/cli.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/near-sdk-js/lib/cli/utils.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/near-sdk-js/src/cli/cli.ts

+6
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ async function createMethodsHeaderFile(rollupTarget: string, verbose = false) {
342342

343343
const mod = await import(`${PROJECT_DIR}/${rollupTarget}`);
344344
const exportNames = Object.keys(mod);
345+
if (exportNames.includes('panic')) {
346+
signal.error(
347+
"'panic' is a reserved word, please use another name for contract method"
348+
);
349+
process.exit(1);
350+
}
345351
const methods = exportNames.reduce(
346352
(result, key) => `${result}DEFINE_NEAR_METHOD(${key})\n`,
347353
""

Diff for: packages/near-sdk-js/src/cli/utils.ts

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export async function executeCommand(
2828
}
2929
if (code != 0) {
3030
signale.error(`Command failed: ${command}`);
31+
32+
const failDueToNameConflict = stderr.match(/conflicting types for '([a-zA-Z0-9_]+)'/);
33+
if (failDueToNameConflict.length > 1) {
34+
signale.error(`'${failDueToNameConflict[1]}' is a reserved word, please use another name for contract method"`);
35+
}
3136
}
3237
if (stderr && verbose) {
3338
signale.error(`Command stderr: ${stderr}`);

0 commit comments

Comments
 (0)