Plugin_not_installed when extending IonicErrorHandler


#1

I’m trying to extend the IonicErrorHandler to report errors using Sentry. Part of this includes version tracking, so I’m trying to use the plugin AppVersion to get the current version, and set it on the Sentry plugin.

import { Injectable } from '@angular/core';
import { ErrorHandler } from '@angular/core';  
import { IonicErrorHandler } from 'ionic-angular';
import { AppVersion } from '@ionic-native/app-version';
import Raven from 'raven-js';

Raven  
  .config('<api key>', { 
    dataCallback: data => {

      if (data.culprit) {
        data.culprit = data.culprit.substring(data.culprit.lastIndexOf('/'));
      }

      var stacktrace = data.stacktrace || data.exception && data.exception.values[0].stacktrace;
      
      if (stacktrace) {
        stacktrace.frames.forEach(function (frame) {
          frame.filename = frame.filename.substring(frame.filename.lastIndexOf('/'));
        });
      }
    } 
  }).install();

@Injectable()
export class SentryErrorHandler extends IonicErrorHandler implements ErrorHandler {

  constructor(private appVersion: AppVersion) {
    // Call super constructor
    super();

    // Configure raven
    appVersion.getVersionNumber().then(version => {
      this.configureRaven(version);
    });
  }

  configureRaven(version) {
    Raven.setRelease(version);
  }

  handleError(error) {
    super.handleError(error);

    try {
      Raven.captureException(error.originalError || error);
    }
    catch(e) {
      console.error(e);
    }
  }
}

However, I get the error

Uncaught (in promise): plugin_not_installed

The plugin is installed, as is the node library, and I can use AppVersion inside my other controllers without any problems.

I’m adding it to the providers as follows:

providers: [
  ...
  AppVersion,
  { provide: ErrorHandler, useClass: SentryErrorHandler }
]

#2

@BenedictLewis did you ever found a solution or did you just decided to hardcode the version number?


#3

@reedrichards were you also facing this issue?

It seems to be happening in a random (but small) number of iOS devices only.


#4

Finally I “hardcoded” the version number in my code

Anyway I was using a plugin to display the version number which was also a bit glitchy, therefore setting a constant/variable for the version number in my code kind of solve two issues

Hope that helps you