Using Sentry with Oclif for CLI

Hi all,

when using sentry, the following sends a message

import * as Sentry from "@sentry/node";

Sentry.init({
   dsn: "http://id@host/number",
});

Sentry.captureMessage('testing sentry 2');

Using the exact same in oclif’s run function fails without any message:

async run(): Promise<void> {
  const { flags } = this.parse(FileName)

  Sentry.init({
    dsn: 'http://id@host/number',
  })

  Sentry.captureMessage('testing sentry 3')
  // further code, runs

How can this be debugged ?

This is the error i get

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
TypeError: domain.enter is not a function
1 Like

Code to recreate the issue

import {Command} from '@oclif/command`
import * as Sentry from '@sentry/node`

export default class MyBaseCommand extends Command {
  async init() {
    Sentry.init({dsn: "my-dns"})
  }

  async catch(err: any) {
    Sentry.captureException(e)
    super.catch(err)
  }

  async finally() {
    Sentry.close()
  }
}

// src/commands/test.js

import MyBaseCommand from '../src/BaseCommand`

export default class Test extends MyBaseCommand {
  run() {
    this.log("Running")
 }
}
1 Like