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

ui: fix errors doesn't display #794

Merged
merged 6 commits into from
Nov 13, 2020

Conversation

baurine
Copy link
Collaborator

@baurine baurine commented Nov 11, 2020

Currently when we kill the TiDB, the dashboard doesn't display the error on the page when requesting API.

Reason: we store the error message in err.message, but sometimes when we access err.message later we get undefined, still don't know the exact reason.

Fix: store the error message in err.msg field instead and it works fine.

After fixing:

WeCom20201111-154611@2x

@baurine
Copy link
Collaborator Author

baurine commented Nov 11, 2020

@breeswish PTAL, thanks!

@baurine baurine marked this pull request as draft November 11, 2020 08:30
@baurine
Copy link
Collaborator Author

baurine commented Nov 11, 2020

It seems to break the CI, let me have a look.

@baurine baurine marked this pull request as ready for review November 11, 2020 08:34
ui/lib/client/index.tsx Outdated Show resolved Hide resolved
@baurine baurine changed the title ui: fix errors doesn't show bug ui: fix the bug that errors doesn't display Nov 11, 2020
@baurine baurine changed the title ui: fix the bug that errors doesn't display ui: fix errors doesn't display Nov 11, 2020
This reverts commit 684db55.
reason: use spread syntax for Error object will miss the message property, because it is a non-enumerable property
@baurine baurine marked this pull request as draft November 12, 2020 07:16
@baurine
Copy link
Collaborator Author

baurine commented Nov 12, 2020

Get the root cause of this issue finally. It is because the message property of the Error object is a non-enumerable property, its value will miss when using spread syntax (I use it somewhere but not everywhere).

Ref: https://stackoverflow.com/a/59874261/2998877

Some tests:

function testError() {
  const err = new Error('test error message')
  console.log(err) // Error: test error message
  console.log({ ...err }) // {}
  console.log('message:', err.message) // message: test error message
  console.log(Object.keys(err)) // []
  console.log(Object.getOwnPropertyDescriptor(err, 'message')) // {value: "test error message", writable: true, enumerable: false, configurable: true}

  err.message = 'modified message'
  err.msg = 'test err.msg'
  console.log(err) // Error: test error message
  console.log({ ...err }) // {msg: "test err.msg"}
  console.log('message:', err.message) // message: modified message
  console.log(Object.keys(err)) // ["msg"]
  console.log(Object.getOwnPropertyDescriptor(err, 'message')) // {value: "modified message", writable: true, enumerable: false, configurable: true}
}

function testCommonObj() {
  function Animal(name) {
    Object.defineProperty(this, 'name', {
      value: name,
      writable: true,
      enumerable: false,
      configurable: true,
    })
  }
  const animal = new Animal('a dog')
  console.log(animal) // Animal {name: "a dog"}
  console.log({ ...animal }) // {}
  console.log(Object.keys(animal)) // []
  console.log(Object.getOwnPropertyDescriptor(animal, 'name')) // {value: "a dog", writable: true, enumerable: false, configurable: true}

  animal.name = 'a cat'
  animal.color = 'white'
  console.log(animal) // Animal {color: "white", name: "a cat"}
  console.log({ ...animal }) // {color: "white"}
  console.log(Object.keys(animal)) // ["color"]
  console.log(Object.getOwnPropertyDescriptor(animal, 'name')) // chart.js:109 {value: "a cat", writable: true, enumerable: false, configurable: true}
}

@baurine baurine marked this pull request as ready for review November 12, 2020 07:34
@baurine
Copy link
Collaborator Author

baurine commented Nov 12, 2020

@breeswish update it, PTAL, thanks!

Copy link
Member

@breezewish breezewish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice dig!

@baurine baurine merged commit 1ff0f33 into pingcap:master Nov 13, 2020
@baurine baurine deleted the fix-error-not-show-bug branch November 13, 2020 01:41
breezewish pushed a commit that referenced this pull request Nov 26, 2020
breezewish added a commit that referenced this pull request Nov 26, 2020
* misc: Increase ulimit to 65535 for test env (#756)
* test: Fix frontend CI (#752)
* ui: fix dayjs i18n (#755)
* ui: handle error globally (#757)
* statement, slow_query: support all fields in list page (#749)
* ui: memorize expand/collapse full text in detail pages (#775)
* ui: break loop dependencies (#771)
* ui: fix browser compatibility check (#776)
* ui: Refine store location, add zoom and pan (#772)
* ui: show disk usage information for statement and slow query (#777)
* ui: use qps instead of ops (#786)
* statement: support export (#778)
*: Fix slow query and start_ts not working in some cases (#793)
* ui: fix errors doesn't display (#794)
* ui: fix the error message doesn't show correct (#799)
* slow_queries: support export (#792)
* ui: add MySqlFormatter to customize the sql formatter (#805)
*: fix query statement detail error cause by round (#806)
* ui: copy original content instead of formatted content for CopyLink (#802)
* add min height of topology canvas (#804)
* metrics: Support customize Prometheus address (#808)
* clusterinfo: Refine (#815)
* ui: Open statement and slow log in new tab (#816)
* ui: add more time field for slow query detail page (#810)
* slowlog: Improve descriptions (#817)
* build: add action to check release-version is changed for release branch
* Release v2020.11.26.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants