JS console output error traps (#7968)

This commit is contained in:
Jaco 2022-08-08 07:40:08 +02:00 committed by GitHub
parent deb0adf366
commit 92ee8c9e6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 32 deletions

View File

@ -69,7 +69,7 @@
"@babel/runtime": "^7.18.9",
"@crustio/crust-pin": "^1.0.0",
"@pinata/sdk": "^1.1.26",
"@polkadot/dev": "^0.67.88",
"@polkadot/dev": "^0.67.89",
"@types/chart.js": "^2.9.37",
"@types/file-saver": "^2.0.5",
"@types/jest": "^28.1.6",
@ -104,7 +104,7 @@
"@polkadot/hw-ledger": "^10.1.3",
"@polkadot/keyring": "^10.1.3",
"@polkadot/networks": "^10.1.3",
"@polkadot/phishing": "^0.18.2",
"@polkadot/phishing": "^0.18.4",
"@polkadot/rpc-augment": "^9.1.1",
"@polkadot/rpc-core": "^9.1.1",
"@polkadot/rpc-provider": "^9.1.1",

View File

@ -14,7 +14,7 @@
"dependencies": {
"@babel/core": "^7.18.10",
"@babel/polyfill": "^7.12.1",
"@polkadot/dev": "^0.67.88",
"@polkadot/dev": "^0.67.89",
"@polkadot/react-components": "^0.119.2-22-x",
"electron-log": "^4.4.8",
"electron-updater": "^4.6.5"

View File

@ -18,7 +18,7 @@
"@babel/runtime": "^7.18.9",
"@polkadot/apps-config": "^0.119.2-22-x",
"@polkadot/apps-routing": "^0.119.2-22-x",
"@polkadot/dev": "^0.67.88",
"@polkadot/dev": "^0.67.89",
"@polkadot/react-api": "^0.119.2-22-x",
"@polkadot/react-components": "^0.119.2-22-x",
"@polkadot/react-hooks": "^0.119.2-22-x",

View File

@ -15,7 +15,7 @@
"dependencies": {
"@babel/runtime": "^7.18.9",
"@polkadot/hw-ledger": "^10.1.3",
"@polkadot/phishing": "^0.18.2",
"@polkadot/phishing": "^0.18.4",
"@polkadot/react-components": "^0.119.2-22-x",
"@polkadot/react-hooks": "^0.119.2-22-x",
"@polkadot/util": "^10.1.3",

View File

@ -16,28 +16,48 @@ interface Props {
const format = (value: unknown): string => {
if (isError(value)) {
return value.stack ? value.stack : value.toString();
return value.stack
? value.stack
: value.toString();
} else if (isUndefined(value)) {
return 'undefined';
} else if (isNull(value)) {
return 'null';
} else if (Array.isArray(value)) {
return `[${value.map((value): string => format(value)).join(', ')}]`;
return `[${value.map(format).join(', ')}]`;
} else if (value instanceof Map) {
return `{${[...value.entries()].map(([key, value]): string => (key as string) + ': ' + format(value)).join(', ')}}`;
return `{${[...value.entries()]
.map(([k, v]) => `${(k as string).toString()}: ${format(v)}`)
.join(', ')}}`;
}
// This _could_ fail as well, hence the catch below
return (value as string).toString();
};
const renderEntry = ({ args, type }: Log, index: number): React.ReactNode => (
<div
className={`js--Log ${type}`}
key={index}
>
{args.map((arg): string => format(arg)).join(' ')}
</div>
);
const renderEntry = ({ args, type }: Log, index: number): React.ReactNode => {
try {
return (
<div
className={`js--Log ${type}`}
key={index}
>
{args.map(format).join(' ')}
</div>
);
} catch (error) {
// e.g. this would hit here -
// console.log(api.createType('ProxyType').__proto__)
return (
<div
className={`js--Log ${type} error`}
key={index}
>
Internal error: {(error as Error).stack || (error as Error).message}
</div>
);
}
};
function Output ({ children, className = '', logs }: Props): React.ReactElement<Props> {
return (

View File

@ -2760,7 +2760,7 @@ __metadata:
dependencies:
"@babel/runtime": ^7.18.9
"@polkadot/hw-ledger": ^10.1.3
"@polkadot/phishing": ^0.18.2
"@polkadot/phishing": ^0.18.4
"@polkadot/react-components": ^0.119.2-22-x
"@polkadot/react-hooks": ^0.119.2-22-x
"@polkadot/test-support": 0.119.2-22-x
@ -3148,7 +3148,7 @@ __metadata:
dependencies:
"@babel/core": ^7.18.10
"@babel/polyfill": ^7.12.1
"@polkadot/dev": ^0.67.88
"@polkadot/dev": ^0.67.89
"@polkadot/react-components": ^0.119.2-22-x
"@types/react-dom": ^18.0.6
"@types/tmp": ^0.2.3
@ -3182,7 +3182,7 @@ __metadata:
"@babel/runtime": ^7.18.9
"@polkadot/apps-config": ^0.119.2-22-x
"@polkadot/apps-routing": ^0.119.2-22-x
"@polkadot/dev": ^0.67.88
"@polkadot/dev": ^0.67.89
"@polkadot/react-api": ^0.119.2-22-x
"@polkadot/react-components": ^0.119.2-22-x
"@polkadot/react-hooks": ^0.119.2-22-x
@ -3217,9 +3217,9 @@ __metadata:
languageName: unknown
linkType: soft
"@polkadot/dev@npm:^0.67.88":
version: 0.67.88
resolution: "@polkadot/dev@npm:0.67.88"
"@polkadot/dev@npm:^0.67.89":
version: 0.67.89
resolution: "@polkadot/dev@npm:0.67.89"
dependencies:
"@babel/cli": ^7.18.10
"@babel/core": ^7.18.10
@ -3308,7 +3308,7 @@ __metadata:
polkadot-exec-rollup: scripts/polkadot-exec-rollup.mjs
polkadot-exec-tsc: scripts/polkadot-exec-tsc.mjs
polkadot-exec-webpack: scripts/polkadot-exec-webpack.mjs
checksum: c7aa38e12009677df7a385fd5d86b4753e14b27b2a9fd8e44e25c376e6155fbfcde7d51f626f804ae605a995a7e9740eb31fda8c4de79a8347d4d2fda2326ce2
checksum: dcdb286b5e5ae6fa56760f545f92547a13eaf8745df54e28386efe80b69adc756ca9354a08751069fb75d8d767dfcdd3c2282eacc8a86ebc1722bb8d034e3d92
languageName: node
linkType: hard
@ -3415,15 +3415,15 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/phishing@npm:^0.18.2":
version: 0.18.2
resolution: "@polkadot/phishing@npm:0.18.2"
"@polkadot/phishing@npm:^0.18.4":
version: 0.18.4
resolution: "@polkadot/phishing@npm:0.18.4"
dependencies:
"@babel/runtime": ^7.18.9
"@polkadot/util": ^10.1.2
"@polkadot/util-crypto": ^10.1.2
"@polkadot/x-fetch": ^10.1.2
checksum: b27bc79705b1c25b464cc97bb62c96c21adfedca8723a4df786ae72c590a2ca91518ef63507ee5f73ee1d5efd6aa2637dcc2febfcb2023f271064a9ff6a03b6b
"@polkadot/util": ^10.1.3
"@polkadot/util-crypto": ^10.1.3
"@polkadot/x-fetch": ^10.1.3
checksum: 28c5b3b92007658fbc16aa8cad7101cc559b2763b43b7ca7b88d5964222438bc24871b0371bd6692785e76d1da4e97b704c6f28d030262d73676135e2e6512f5
languageName: node
linkType: hard
@ -3894,7 +3894,7 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/x-fetch@npm:^10.1.2, @polkadot/x-fetch@npm:^10.1.3":
"@polkadot/x-fetch@npm:^10.1.3":
version: 10.1.3
resolution: "@polkadot/x-fetch@npm:10.1.3"
dependencies:
@ -16042,7 +16042,7 @@ __metadata:
"@babel/runtime": ^7.18.9
"@crustio/crust-pin": ^1.0.0
"@pinata/sdk": ^1.1.26
"@polkadot/dev": ^0.67.88
"@polkadot/dev": ^0.67.89
"@types/chart.js": ^2.9.37
"@types/file-saver": ^2.0.5
"@types/jest": ^28.1.6