<commit_before>/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./sentry-api.android.d.ts" />
import { Common } from './sentry.common';
import * as application from 'tns-core-modules/application';
import * as utils from 'tns-core-modules/utils/utils';
import { stringify } from "./utils/utils";
import * as ErrorStackParser from 'error-stack-parser';


export class Sentry extends Common {


    constructor() {
        super();
    }

    /**
     * init
     */
    public static init(dsn: string) {

        try {
            io.sentry.Sentry.init(dsn, new io.sentry.android.AndroidSentryClientFactory(utils.ad.getApplicationContext()));
        } catch (error) {
            console.log('[Sentry - Android] Exeption on init: ', error);
        }
        application.on(application.uncaughtErrorEvent, args => {
            try {
                io.sentry.Sentry.capture(args);
            } catch (e) {
                console.log('[Sentry - Android] Exeption on capture: ', e);
            }
        });
    }

    private static getErrorDetails(error: any): Error {

        console.log('getErrorDetails');
        if (error.android) {
            console.log('error.android');
            error = error.android;
        }
        // console.log(error);
        // console.dir(error);
        if (error instanceof Error) {
            console.log('is a new Error ');
            // console.log((error as Error).name);
            // console.log((error as Error).message);
            // console.log((error as Error).stack);
            return error;
        } else if (typeof error === 'string') {
            console.log('this is a string error');
            console.log(error); 
            console.dir(new Error(error));
            // let newError = new Error();
            // newError.message = error.toString();
            // newError.name = 'Error';
            // newError.stack = (error as any ).
            return new Error((error as any).originalStack);

        }


        if (error.android) {
            console.log('error.android');
            error = error.android;
        }
        return error;
    }



    /**
     * capture
     */
    public static capture(error: any) {
        try {

            let errorWithDetails = this.getErrorDetails(error);
            let stackArray = Array.of<java.lang.StackTraceElement>();

            const parsedStack: ErrorStackParser.StackFrame[] = ErrorStackParser.parse(errorWithDetails);<commit_msg>fix(android): fix for when the error is not an Error Object<commit_after>/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./sentry-api.android.d.ts" />
import { Common } from './sentry.common';
import * as application from 'tns-core-modules/application';
import * as utils from 'tns-core-modules/utils/utils';
import { stringify } from "./utils/utils";
import * as ErrorStackParser from 'error-stack-parser';


export class Sentry extends Common {


    constructor() {
        super();
    }

    /**
     * init
     */
    public static init(dsn: string) {

        try {
            io.sentry.Sentry.init(dsn, new io.sentry.android.AndroidSentryClientFactory(utils.ad.getApplicationContext()));
        } catch (error) {
            console.log('[Sentry - Android] Exeption on init: ', error);
        }
        application.on(application.uncaughtErrorEvent, args => {
            try {
                io.sentry.Sentry.capture(args);
            } catch (e) {
                console.log('[Sentry - Android] Exeption on capture: ', e);
            }
        });
    }

    private static getErrorDetails(error: any): Error {

        if (error.android) {
            error = error.android;
        }
        if (error instanceof Error) {
            return error;
        } else if (typeof error === 'string') {
            return new Error((error as any).originalStack);
        }

        if (error.android) {
            error = error.android;
        }
        return new Error(JSON.stringify(error));
    }



    /**
     * capture
     */
    public static capture(error: any) {
        try {

            let errorWithDetails = this.getErrorDetails(error);
            let stackArray = Array.of<java.lang.StackTraceElement>();

            const parsedStack: ErrorStackParser.StackFrame[] = ErrorStackParser.parse(errorWithDetails);
{'fraction_non_alphanumeric': 0.13238289205702647, 'fraction_numerical': 0.0, 'mean_word_length': 1.9724277067921991, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3355743', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1198, 'n_words': 270}