1.0.51 • Published 3 years ago

panic-overlay v1.0.51

Weekly downloads
304
License
Unlicense
Repository
github
Last release
3 years ago

panic-overlay BETA 💥✨Build Status NPM

A lightweight standalone plain JS alternative to react-error-overlay that is not tied to React / Webpack and works with any framework or even without one.

If you miss that thing from create-react-app but do not want to use that framework (e.g. you want to use Parcel as a lightweight zero-configuration alternative) — here you go!

Features

  • Displays runtime errors in browsers
  • Minimalistic implementation (bare DOM API), easily hackable
  • Full sourcemap support (shows original code, not transpiled)
  • Clickable locations (opens in VS Code), see the notes here
  • Uncluttered stacktraces (collapses third party library calls)

How It Looks

Installation

npm install panic-overlay
import 'panic-overlay' // should be the very first import in your app!

Using Without A Bundler

All-in-one browser bundle (batteries included), served from a CDN of your choice. Creates a global panic object.

<script src="https://unpkg.com/panic-overlay"></script>

Demos

Here's how you can find an example usage of panic-overlay with various bundlers:

git clone https://github.com/xpl/panic-overlay.git
cd panic-overlay
npm install
EnvironmentRun withSource folder
<script> tagnpm run demo-no-bundlerdemo/no-bundler
Parcelnpm run demo-parcel-vanillademo/parcel-vanilla
Parcel (React JSX)npm run demo-parcel-reactdemo/parcel-react
Webpacknpm run demo-webpack-vanillademo/webpack-vanilla
Snowpacknpm run demo-snowpack-vanillademo/snowpack-vanilla

Disabling Automatic Error Handling

Once imported, panic-overlay shows itself whenever an uncaught error occurs in a browser. This can be undesirable in a production environment. You can disable that behavior in run-time:

import panic from 'panic-overlay'

panic.configure ({ handleErrors: false })

Although it is better to not import the panic-overlay in a production build, to minimize the bundle size. Unfortunately, there is no universal way to do a conditional module import at compile-time — in each bundler/framework it is achieved in its own way.

Showing Manually

panic (error) // where error is either an instance of an Error or a string taken from Error.stack

VS Code Notes

Currently there is a problem with automatically determining the full file paths (at least, when using Parcel bundler), so you need to provide it manually, otherwise the error locations won't be clickable:

import panic from 'panic-overlay'

panic.configure ({ projectRoot: '/full/path/to/my/project' })

Custom Click Handler

You can intercept clicks on call stack entries. For the entry format, see this.

panic.configure ({
    stackEntryClicked (entry) {
        alert (`Clicked on ${entry.fileRelative}:${entry.line}:${entry.column}`)
    }
})

Hacking

The panic-overlay is just a GUI for the stacktracey library that provides all the magic related to callstack parsing, source code extraction and filtering of the clutter. I also maintain that library, so any contributions to its code are welcome as well.

I highly appreciate any help from the community with the following:

  • Testing with various module bundlers / frameworks
  • Implementing parsing of React JSX errors in stacktracey (see more here)
  • Determining the full file paths for clickable locations
  • Animations & better layout (probably need to center it for wide screens)

...One More Thing™

There is also a way to improve your Node errors (and the overall debug output) legibility by using the Ololog library which is built on the same stack and is maintained by me also. Check it out!

const log = require ('ololog').handleNodeErrors () // intercepts process errors

Color logging with displaying of the log call location (file + line), so you can quickly find out from the logs, where it was called in the code:

log.bright.green ('Syncing order books...')
1.0.51

3 years ago

1.0.50

3 years ago

1.0.48

3 years ago

1.0.47

3 years ago

1.0.46

3 years ago

1.0.49

3 years ago

1.0.44

3 years ago

1.0.43

3 years ago

1.0.45

3 years ago

1.0.42

4 years ago

1.0.41

4 years ago

1.0.39

5 years ago

1.0.38

5 years ago

1.0.37

5 years ago

1.0.34

5 years ago

1.0.33

5 years ago

1.0.32

5 years ago

1.0.31

5 years ago

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago