Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

error handling: no error is returned in case of error #145

Closed
robertkowalski opened this issue May 30, 2018 · 6 comments
Closed

error handling: no error is returned in case of error #145

robertkowalski opened this issue May 30, 2018 · 6 comments
Labels

Comments

@robertkowalski
Copy link
Contributor

it seems very often nothing happens / is returned from the error callback:

    const account_name = 'user'
    const pos = 0
    const offset = 10

    eos.getActions({
      account_name, pos, offset
    }, (err, res) => {
      if (err) return cb(err)  // expected to be called

      return cb(null, res)
    })

Assumption: a promise / the promises used internally missing a catch handler, that is passing the error to the callback based API. This appears in the global node process log:

(node:28736) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
api error => { message: 'Invalid cast from type \'object_type\' to string',
  file: 'variant.cpp',
  line_number: 565,
  method: 'get_string' } http://127.0.0.1:8888/v1/history/get_actions {"account_name":{"account_name":"user","pos":0,"offset":10}}
{ Error: {"code":500,"message":"Internal Service Error","error":{"code":7,"name":"bad_cast_exception","what":"Bad Cast","details":[{"message":"Invalid cast from type 'object_type' to string","file":"variant.cpp","line_number":565,"method":"get_string"}]}}
    at /Users/robert/bitfinex/bfx-coin-eos-js/node_modules/eosjs-api/lib/apigen.js:115:23
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7) status: 500, statusText: 'Internal Server Error' }

Why do we need this?

Given we want to provide the error in a request / response context we can't rely on the global "uncaughtPromiseException" handler.

@jcalfee jcalfee added the bug label May 30, 2018
jcalfee pushed a commit that referenced this issue May 30, 2018
jcalfee pushed a commit to EOSIO/eosjs-api that referenced this issue May 30, 2018
@jcalfee
Copy link
Contributor

jcalfee commented May 30, 2018

published [email protected]

@jcalfee jcalfee closed this as completed May 30, 2018
@ycryptx
Copy link

ycryptx commented Jun 7, 2018

@jcalfee I'm encountering this too on both @13.0.1 and @14.0.0
It would be nice to get a rejection promise back when there's a contract assertion error :D

@jcalfee
Copy link
Contributor

jcalfee commented Jun 7, 2018

I need to see your example. It is working in this case:

> eos.transfer('noacct', 'acct', '1 SYS', 'memo', (err, res)=> console.error('ERROR', err))
undefined
> api error => { message: 'action\'s code account \'eosio.token\' does not exist',
  file: 'controller.cpp',
  line_number: 1420,
  ...

ERROR {"code":500,"message":"Internal Service Error","error":{"code":3040000,"name":"transaction_exception","what":"transaction exception","details":[{"message":"action's code account 'eosio.token' does not exist","file":"controller.cpp","line_number":1420,"method":"validate_referenced_accounts"}]}}

@jcalfee
Copy link
Contributor

jcalfee commented Jun 7, 2018

Also works for a read-only api:

> eos.getActions('eosio', 'a', 0, (err, res)=> {console.error('ERROR', err); console.log('RES', res)})
undefined
> api error => { message: 'Couldn\'t parse int64_t',
  ...
ERROR { Error: {"code":500,"message":"Internal Service Error","error":{"code":4,"name":"parse_error_exception","what":"Parse Error","details":[{"message":"Couldn't parse int64_t","file":"string.cpp","line_number":100,"method":"to_int64"}]}}
    at /home/jcalfee/eosjs/eosjs/node_modules/eosjs-api/lib/apigen.js:115:23
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7) status: 500, statusText: 'Internal Server Error' }
RES undefined

@ycryptx
Copy link

ycryptx commented Jun 7, 2018

@jcalfee hey james.

I get this internal error message:
{"code":500,"message":"Internal Service Error","error":{"code":3050003,"name":"eosio_assert_message_exception","what":"eosio_assert_message assertion failure","details":[{"message":"assertion failure with message: Create() can only be called once","file":"wasm_interface.cpp","line_number":930,"method":"eosio_assert"},{"message":"","file":"apply_context.cpp","line_number":60,"method":"exec_one"}]}} (node:12004) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: Cannot read property 'data' of undefined

I have this assert statement in my contract function
eosio_assert(itr_meta->created != 1, "Create() can only be called once");

and in my javascript I call:

  eos.transaction({
  actions: [
    {
      account: data.cid,
      name: 'create',
      authorization: [{
        actor: data.cid,
        permission: 'active'
      }],
      data: {
        username : data.username,
      }
      }
    ]
  })  .then(rules => {res.status(200).send({message: "Repo rules were set successfully", rules})})
  .catch(err => {
    console.log(err.response.data);
    res.status(400).send(err: err.response.data);
  });

@jcalfee
Copy link
Contributor

jcalfee commented Jun 13, 2018

You can only create an asset once. After that you need to call issue to issue some or all of the asset you just created to another account. Finally, that last account can call transfer..

@jcalfee jcalfee added help and removed bug labels Jun 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants