| 220 | |
| 221 | if (typeof window !== 'undefined' && 'customElements' in window) { |
| 222 | class ErrorOverlay extends HTMLElement { |
| 223 | root: ShadowRoot; |
| 224 | closeOnEsc: (e: KeyboardEvent) => void; |
| 225 | closeOnReload: () => void; |
| 226 | |
| 227 | constructor(props: ErrorOverlayProps, links = true) { |
| 228 | super(); |
| 229 | |
| 230 | const { error, pilet, errorType } = props; |
| 231 | |
| 232 | this.root = this.attachShadow({ mode: 'open' }); |
| 233 | this.root.appendChild(createTemplate()); |
| 234 | |
| 235 | codeframeRE.lastIndex = 0; |
| 236 | const hasFrame = error.frame && codeframeRE.test(error.frame); |
| 237 | const message = hasFrame ? error.message.replace(codeframeRE, '') : error.message; |
| 238 | |
| 239 | if (pilet) { |
| 240 | this.text('.plugin', `[${pilet}] `); |
| 241 | } |
| 242 | |
| 243 | this.text('.message-body', message.trim()); |
| 244 | |
| 245 | const [file] = (error.loc?.file || error.id || 'unknown file').split(`?`); |
| 246 | |
| 247 | if (error.loc) { |
| 248 | this.text('.file', `${file}:${error.loc.line}:${error.loc.column}`, links); |
| 249 | } else if (error.id) { |
| 250 | this.text('.file', file); |
| 251 | } |
| 252 | |
| 253 | if (hasFrame) { |
| 254 | this.text('.frame', error.frame!.trim()); |
| 255 | } |
| 256 | |
| 257 | this.text('.stack', error.stack.split('\n').slice(0, 15).join('\n'), links); |
| 258 | |
| 259 | convertError(error, 0, 15).then((newStack) => { |
| 260 | this.text('.stack', newStack, links); |
| 261 | }); |
| 262 | |
| 263 | this.root.querySelector('.window')!.addEventListener('click', (e) => { |
| 264 | e.stopPropagation(); |
| 265 | }); |
| 266 | |
| 267 | this.addEventListener('click', () => { |
| 268 | this.close(); |
| 269 | }); |
| 270 | |
| 271 | this.closeOnEsc = (e: KeyboardEvent) => { |
| 272 | if (e.key === 'Escape' || e.code === 'Escape') { |
| 273 | this.close(); |
| 274 | } |
| 275 | }; |
| 276 | |
| 277 | this.closeOnReload = () => this.close(); |
| 278 | |
| 279 | window.addEventListener('pilets-reloaded', this.closeOnReload); |
nothing calls this directly
no outgoing calls
no test coverage detected