npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

expo-error-log

v1.1.3

Published

An error loging utility for Expo

Downloads

128

Readme

expo-error-log

An error logging utility for Expo

install with

npm install expo-error-log

or

yarn add expo-error-log

also you must install expo-constants

expo install expo-constants

in app.json add

{
  "expo": {
    "version": "1.0.1",
    ...,
    "hooks": {
      "postPublish" : [
        {
          "file":"expo-error-log"
        }
      ]
    }
  }
}

Now, everytime you expo publish, the source maps of your application will be saved in your project root in a .source_maps folder.

Next, add a script so we can easily excecute the expo-error-log cli from the command line. In package.json add:

{
  "main": "node_modules/expo/AppEntry.js",
  ...
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject",
    // add this line
    "expo-error-log": "expo-error-log"
  },

You must provide your own method to push errors to a database of some kind. In App.js import the hook with

import { setErrorHandler } from 'expo-error-log/setErrorHandler.js'

and set up your logging service. (hint: If you place it in the render method of your main app component, then statefull data that you want to log will always be fresh!) Here is an example of an error handler, it uses firebase realtime database

const myErrorHandler = e => {
  firebase.database().ref('/errors/').push(e)
  Alert.alert(
    "ALERT", 
    "Sorry there was an error, click to restart the app",
    [
      {
        text:'OK',
        onPress:()=>Updates.reload()
      }
    ],
    {cancelable: false}
  )
}

setErrorHandler({
  cb: myErrorHandler,
  // optional data propery for any extra data you wish to log
  data: {
    currentView: this.state.currentView,
    userName: this.state.userName,
    appVersion: Constants.manifest.version,
    OS: Platform.OS,
    OSVersion: Platform.Version
  }
})

To fetch, symbolicate, parse, and print your error logs to the console, simply run

npm run expo-error-log "curl myDatabaseRestApiEndpoint"

For example with firebase, if the database rules are set to read: true for the errors node

npm run expo-error-log "curl https://myProjectName.firebaseio.com/errors.json"

Alternatively, you can provide a custom function to fetch your errors from the database. Pass the argument with followed by a path to your fetching script, relative to the project root.

For example, if I placed my function in /myExpoProject/errorFetch/myErrorFetchFunc.js then npm run expo-error-log with ./errorFetch/myErrorFetchFunc.js would work. Note that myErrorFetchFunc.js must export a function directly, for example:

const firebase = require('firebase');

const myLogScript = async()=>{
    firebase.initializeApp(env.firebaseConfig);
    await firebase.auth().signInWithEmailAndPassword(env.myLoginEmail,env.myLoginPassword)
    .catch(e=> console.log(e));
    let errors;
    await firebase.database().ref('/errors/').once('value',function(snap){
        errors = snap.val();
    })
    return(errors)
};

module.exports = myLogScript

This function can be either synchronous or async (returning a Promise), and return an array or an object, like firebase does.

alt text

If you want to save the output of expo-error-log, you can use this bash command

npm run expo-error-log with ./myScript > myLogFile.txt

or to append to the file

npm run expo-error-log with ./myScript >> myLogFile.txt

Or, you can use only the part of the package which symbolicates and parses your stack traces, and do with them as you please.

// myErrorPrintingScript.js
const { symbolicate } = require('expo-error-log/symbolicate.js');
const myLogFetchingScript = require('./helpers/myLogFetchingScript.js');

myLogFetchingScript().then(errors=>{
    symbolicate(errors).then(log=>{
        log.errors.forEach(e=>console.log(e))
    })
})

then node myErrorPrintingScript.js

alt text

symbolicate.js returns a log in this shape

{
    timestamp: Date.now(),
    datetime: new Date().toUTCString(),
    errors:[
        {
            isFatal: true,
            timestamp: -1,
            datetime: '',
            message: '',
            userData: {},
            mapId: '',
            mapPath: '',
            err: undefined,
            stack: [
                {
                    name: '',
                    source: '',
                    line: -1,
                    column: -1,
                    shortSource: ''
                },
            ]
        },
    ]
};