broxus / locklift

Node JS framework for working with Everscale and Venom contracts. Inspired by Truffle and Hardhat. Helps you build, test, run and maintain your smart contracts.
Apache License 2.0
51 stars 31 forks source link

Handle Better Error Messages #13

Closed river-hue closed 1 year ago

river-hue commented 2 years ago

At the current moment, there are a lot of error-cases where locklift doesn't provide very useful errors. This makes development much harder.Here are some suggested errors that should be catched by locklift and some suggestions.

Calling method on Non-Deployed Contract:

Current Behavior:

let WalletContr = await locklift.factory.getAccount("Wallet")
let contract = await locklift.giver.deployContract({ ... })

/// Set to Zero:
contract.setAddress(locklift.utils.zeroAddress)

/// When calling a method you get:
/// TypeError: Cannot read properties of undefined (reading 'boc')
///   at Contract.call (node_modules/locklift/locklift/contract/index.js:116:9)
let owner = await contract.call({method: 'owner'})

Suggested behavior:

/// When calling a method you get:
/// LockliftError: Contract "0x000...000": Method 'owner': Contract not deployed
///   at Contract.call (node_modules/locklift/locklift/contract/index.js:116:9)
let owner = await contract.call({method: 'owner'})

Calling method with wrong parameter type:

Current Behavior:

let WalletContr = await locklift.factory.getAccount("Wallet")
let contract = await locklift.giver.deployContract({ ... })

/// When calling a method you get:
/// Create run message failed: Wrong data format:
/// "bar"
await contract.call({
    method: 'takeFoo'
    /// params: { foo: '' } (Correct Params)
    params: { foo: 123 }
})

Suggested behavior:


/// When calling a method you get:
/// LockLiftError: Contract "0x000...000": Method 'takeFoo':
/// parameter 'foo': value 123: wrong data format must be type string not number
await contract.call({
    method: 'takeFoo'
    /// params: { foo: '' } (Correct Params)
    params: { foo: 123 }
})

Calling method with missing parameter

Current Behavior:

let WalletContr = await locklift.factory.getAccount("Wallet")
let contract = await locklift.giver.deployContract({ ... })

/// When calling a method you get:
/// Create run message failed: Wrong data format: 
///   null
await contract.call({
    method: 'takeFoo'
    /// params: { foo: '' } (Correct Params)
    params: { not_foo: ''}
})

Suggested behavior:


/// When calling a method you get:
/// LockLiftError: Contract "0x000...000": Method 'takeFoo':
/// parameter 'foo': value undefined: wrong data format must be type string not number
await contract.call({
    method: 'takeFoo'
    /// params: { foo: '' } (Correct Params)
    params: { not_foo: ''}
})
30mb1 commented 2 years ago

Very useful comments, thank you! We are in process of big code refactoring right now, including typescript support and etc. I will consider your points