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

Cannot read property 'name' of null #1055

Closed
adyshimony opened this issue Jan 29, 2018 · 2 comments

Comments

@adyshimony
Copy link

commented Jan 29, 2018

I am getting this error only on one file.
Removing the try block solves the issue.

ERROR:

> standard "./rest-api/src/routes/api/accountTx.ts"

standard: Unexpected linter output:

TypeError: Cannot read property 'name' of null
    at checkForViolation (/home/adys/Sources/supernode/node_modules/eslint/lib/rules/no-shadow-restricted-names.js:33:39)
    at EventEmitter.CatchClause (/home/adys/Sources/supernode/node_modules/eslint/lib/rules/no-shadow-restricted-names.js:64:17)
    at EventEmitter.emit (events.js:165:20)
    at NodeEventGenerator.applySelector (/home/adys/Sources/supernode/node_modules/eslint/lib/util/node-event-generator.js:265:26)
    at NodeEventGenerator.applySelectors (/home/adys/Sources/supernode/node_modules/eslint/lib/util/node-event-generator.js:294:22)
    at NodeEventGenerator.enterNode (/home/adys/Sources/supernode/node_modules/eslint/lib/util/node-event-generator.js:308:14)
    at CodePathAnalyzer.enterNode (/home/adys/Sources/supernode/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:602:23)
    at CommentEventGenerator.enterNode (/home/adys/Sources/supernode/node_modules/eslint/lib/util/comment-event-generator.js:98:23)
    at Traverser.enter (/home/adys/Sources/supernode/node_modules/eslint/lib/eslint.js:929:36)
    at Traverser.__execute (/home/adys/Sources/supernode/node_modules/estraverse/estraverse.js:397:31)

CODE that cause the issue:

import * as express from 'express'
import * as logger from 'winston'
import * as dbUtils from '../../utils/dbUtils'

const router = express.Router()
// return all transactions history for account address
router.get('/:address', async (req, res, next) => {
  try {
    let result = await dbUtils.getAccountAsync(req.params.address)
    return res.json(
    {
      'status': '1',
      'message': 'OK',
      'result': result
    })
  } catch {
      return res.json(
      {
        'status': '0',
        'message': 'ERROR',
        'result': 'not found'
      })
  }
})

module.exports = router

Remark the block:

import * as express from 'express'
import * as logger from 'winston'
import * as dbUtils from '../../utils/dbUtils'

const router = express.Router()
// return all transactions history for account address
router.get('/:address', async (req, res, next) => {
  //try {  <-------------------- here
    let result = await dbUtils.getAccountAsync(req.params.address)
    return res.json(
    {
      'status': '1',
      'message': 'OK',
      'result': result
    })
  //} catch {  <-------------------- here
      return res.json(
      {
        'status': '0',
        'message': 'ERROR',
        'result': 'not found'
      })
  //}  <-------------------- and here
})

module.exports = router

And everything is working now.

> supernode-rest-api@1.0.0 standard-rest-api /home/adys/Sources/supernode
> standard "./rest-api/src/routes/api/accountTx.ts"

standard: Use JavaScript Standard Style (https://standardjs.com)
standard: Run `standard --fix` to automatically fix some problems.
  /home/adys/Sources/supernode/rest-api/src/routes/api/accountTx.ts:2:13: 'logger' is defined but never used.
  /home/adys/Sources/supernode/rest-api/src/routes/api/accountTx.ts:9:5: Expected indentation of 2 spaces but found 4.
  /home/adys/Sources/supernode/rest-api/src/routes/api/accountTx.ts:10:5: Expected indentation of 2 spaces but found 4.
  /home/adys/Sources/supernode/rest-api/src/routes/api/accountTx.ts:11:5: Expected indentation of 6 spaces but found 4.
  /home/adys/Sources/supernode/rest-api/src/routes/api/accountTx.ts:12:7: Expected indentation of 8 spaces but found 6.
  /home/adys/Sources/supernode/rest-api/src/routes/api/accountTx.ts:13:7: Expected indentation of 8 spaces but found 6.
  /home/adys/Sources/supernode/rest-api/src/routes/api/accountTx.ts:14:7: Expected indentation of 8 spaces but found 6.
  /home/adys/Sources/supernode/rest-api/src/routes/api/accountTx.ts:15:5: Expected indentation of 6 spaces but found 4.
  /home/adys/Sources/supernode/rest-api/src/routes/api/accountTx.ts:17:7: Expected indentation of 2 spaces but found 6.
  /home/adys/Sources/supernode/rest-api/src/routes/api/accountTx.ts:17:7: Unreachable code.
  /home/adys/Sources/supernode/rest-api/src/routes/api/accountTx.ts:18:7: Expected indentation of 8 spaces but found 6.
  /home/adys/Sources/supernode/rest-api/src/routes/api/accountTx.ts:19:9: Expected indentation of 10 spaces but found 8.
  /home/adys/Sources/supernode/rest-api/src/routes/api/accountTx.ts:20:9: Expected indentation of 10 spaces but found 8.
  /home/adys/Sources/supernode/rest-api/src/routes/api/accountTx.ts:21:9: Expected indentation of 10 spaces but found 8.
  /home/adys/Sources/supernode/rest-api/src/routes/api/accountTx.ts:22:7: Expected indentation of 8 spaces but found 6.

standard config in package.json:

"standard": {
"parser": "typescript-eslint-parser",
"plugins": [
"typescript"
]
}

Not sure if its elint or standard, opening here too:
eslint/typescript-eslint-parser#439

@stale

This comment has been minimized.

Copy link

commented May 10, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label May 10, 2018

@feross

This comment has been minimized.

Copy link
Member

commented May 11, 2018

Copying from the linked issue, this is the workaround:

ESLint doesn’t support catch clauses without a parameter, as they’re not yet part of JavaScript. Using catch (_) or similar instead should fix the issue.

Mentioned in this comment: eslint/typescript-eslint-parser#439 (comment)

@feross feross closed this May 11, 2018

@lock lock bot locked as resolved and limited conversation to collaborators Aug 9, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
2 participants
You can’t perform that action at this time.