UNPKG

@jbrowse/core

Version:

JBrowse 2 core libraries used by plugins

95 lines (94 loc) 4.79 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const Refresh_1 = __importDefault(require("@mui/icons-material/Refresh")); const Report_1 = __importDefault(require("@mui/icons-material/Report")); const material_1 = require("@mui/material"); const mui_1 = require("tss-react/mui"); const RedErrorMessageBox_1 = __importDefault(require("./RedErrorMessageBox")); const ErrorMessageStackTraceDialog = (0, react_1.lazy)(() => Promise.resolve().then(() => __importStar(require('./ErrorMessageStackTraceDialog')))); const useStyles = (0, mui_1.makeStyles)()(theme => ({ bg: { background: theme.palette.divider, border: '1px solid black', margin: 20, }, iconFloat: { float: 'right', marginLeft: 100, }, })); function parseError(str) { let snapshotError = ''; const findStr = 'is not assignable'; const idx = str.indexOf(findStr); if (idx !== -1) { const trim = str.slice(0, idx + findStr.length); const match = /.*at path "(.*)" snapshot `(.*)` is not assignable/m.exec(trim); if (match) { str = `Failed to load element at ${match[1]}...Failed element had snapshot`; snapshotError = match[2]; } const match2 = /.*snapshot `(.*)` is not assignable/.exec(trim); if (match2) { str = 'Failed to load element...Failed element had snapshot'; snapshotError = match2[1]; } } return snapshotError; } function ErrorButtons({ error, onReset, }) { const { classes } = useStyles(); const [showStack, setShowStack] = (0, react_1.useState)(false); return ((0, jsx_runtime_1.jsxs)("div", { className: classes.iconFloat, children: [typeof error === 'object' && error && 'stack' in error ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: "Get stack trace", children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { onClick: () => { setShowStack(true); }, color: "primary", children: (0, jsx_runtime_1.jsx)(Report_1.default, {}) }) })) : null, onReset ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: "Retry", children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { onClick: onReset, color: "primary", children: (0, jsx_runtime_1.jsx)(Refresh_1.default, {}) }) })) : null, showStack ? ((0, jsx_runtime_1.jsx)(react_1.Suspense, { fallback: null, children: (0, jsx_runtime_1.jsx)(ErrorMessageStackTraceDialog, { error: error, onClose: () => { setShowStack(false); } }) })) : null] })); } function ErrorMessage({ error, onReset, }) { const { classes } = useStyles(); const str = `${error}`; const str2 = str.indexOf('expected an instance of'); const str3 = str2 !== -1 ? str.slice(0, str2) : str; const snapshotError = parseError(str); return ((0, jsx_runtime_1.jsxs)(RedErrorMessageBox_1.default, { children: [str3.slice(0, 10000), (0, jsx_runtime_1.jsx)(ErrorButtons, { error: error, onReset: onReset }), snapshotError ? ((0, jsx_runtime_1.jsx)("pre", { className: classes.bg, children: JSON.stringify(JSON.parse(snapshotError), null, 2) })) : null] })); } exports.default = ErrorMessage;