microsoft / appcenter-sdk-react-native

Development repository for the App Center SDK for React Native
Other
416 stars 136 forks source link

Support ES2022 `cause` to track inner exception stack traces #1014

Closed stefan-schweiger closed 1 year ago

stefan-schweiger commented 1 year ago

Is your feature request related to a problem? Please describe. When you are rethrowing an error with a nicer error message currently the stacktrace of the inner exception gets lost.

try {
  connectToDatabase();
} catch (err) {
  throw new Error("Connecting to database failed.", { cause: err });
}
const logError = (err: Error) => {
  Crashes.trackError(ExceptionModel.createFromError(error));
}

This currently only tracks the stack trace from the new error but not from the inner error.

The Crashed.d.ts file contains a definition for innerException but as far as I can tell this is actually never used in any real code:

Crashes.ExceptionModel = class {
    wrapperSdkName = 'appcenter.react-native';

    constructor(type, message, stack) {
        this.type = type;
        this.message = message;
        this.stackTrace = stack;
    }

    // Error value should have Error type.
    static createFromError(error) {
        return new this(error.name, error.message, error.stack);
    }

    static createFromTypeAndMessage(type, message, stacktrace) {
        return new this(type, message, stacktrace);
    }
};

Describe the solution you'd like ExceptionModel.createFromError should correctly resolve the ES2022 standard field cause and log a correct combined stacktrace.

Describe alternatives you've considered Allow at least to supply an innner exception as a separate paramter (and also implement it for real instead of just providing a typing which no real code).

MikhailSuendukov commented 1 year ago

We have decided not to implement this feature in the foreseeable future. However, we truly appreciate and welcome your contribution!

stefan-schweiger commented 1 year ago

@MikhailSuendukov can you then at least fix the type definitions?