How to use the @sentry/utils.SyncPromise.resolve function in @sentry/utils

To help you get started, we’ve selected a few @sentry/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github getsentry / sentry-javascript / packages / node / src / parsers.ts View on Github external
}

    return parsedFrame;
  });

  // We do an early return if we do not want to fetch context liens
  if (linesOfContext <= 0) {
    return SyncPromise.resolve(frames);
  }

  try {
    return addPrePostContext(filesToRead, frames, linesOfContext);
  } catch (_) {
    // This happens in electron for example where we are not able to read files from asar.
    // So it's fine, we recover be just returning all frames without pre/post context.
    return SyncPromise.resolve(frames);
  }
}
github getsentry / sentry-javascript / packages / node / src / parsers.ts View on Github external
function readSourceFiles(filenames: string[]): PromiseLike<{ [key: string]: string | null }> {
  // we're relying on filenames being de-duped already
  if (filenames.length === 0) {
    return SyncPromise.resolve({});
  }

  return new SyncPromise<{
    [key: string]: string | null;
  }>(resolve => {
    const sourceFiles: {
      [key: string]: string | null;
    } = {};

    let count = 0;
    // tslint:disable-next-line:prefer-for-of
    for (let i = 0; i < filenames.length; i++) {
      const filename = filenames[i];

      const cache = FILE_CONTENT_CACHE.get(filename);
      // We have a cache hit
github getsentry / sentry-javascript / packages / core / src / baseclient.ts View on Github external
exception.value = truncate(exception.value, maxValueLength);
    }

    const request = prepared.request;
    if (request && request.url) {
      request.url = truncate(request.url, maxValueLength);
    }

    if (prepared.event_id === undefined) {
      prepared.event_id = uuid4();
    }

    this._addIntegrations(prepared.sdk);

    // We prepare the result here with a resolved Event.
    let result = SyncPromise.resolve(prepared);

    // This should be the last thing called, since we want that
    // {@link Hub.addEventProcessor} gets the finished prepared event.
    if (scope) {
      // In case we have a hub we reassign it.
      result = scope.applyToEvent(prepared, hint);
    }

    return result;
  }
github getsentry / sentry-javascript / packages / browser / src / backend.ts View on Github external
public eventFromException(exception: any, hint?: EventHint): PromiseLike {
    const syntheticException = (hint && hint.syntheticException) || undefined;
    const event = eventFromUnknownInput(exception, syntheticException, {
      attachStacktrace: this._options.attachStacktrace,
    });
    addExceptionMechanism(event, {
      handled: true,
      type: 'generic',
    });
    event.level = Severity.Error;
    if (hint && hint.event_id) {
      event.event_id = hint.event_id;
    }
    return SyncPromise.resolve(event);
  }
  /**
github getsentry / sentry-javascript / packages / browser / src / backend.ts View on Github external
public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): PromiseLike {
    const syntheticException = (hint && hint.syntheticException) || undefined;
    const event = eventFromString(message, syntheticException, {
      attachStacktrace: this._options.attachStacktrace,
    });
    event.level = level;
    if (hint && hint.event_id) {
      event.event_id = hint.event_id;
    }
    return SyncPromise.resolve(event);
  }
}
github getsentry / sentry-javascript / packages / node / src / integrations / linkederrors.ts View on Github external
public walkErrorTree(error: ExtendedError, key: string, stack: Exception[] = []): PromiseLike {
    if (!isInstanceOf(error[key], Error) || stack.length + 1 >= this._limit) {
      return SyncPromise.resolve(stack);
    }
    return new SyncPromise((resolve, reject) => {
      getExceptionFromError(error[key])
        .then((exception: Exception) => {
          this.walkErrorTree(error[key], key, [exception, ...stack])
            .then(resolve)
            .then(null, () => {
              reject();
            });
        })
        .then(null, () => {
          reject();
        });
    });
  }
}
github getsentry / sentry-javascript / packages / node / src / integrations / linkederrors.ts View on Github external
public handler(event: Event, hint?: EventHint): PromiseLike {
    if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {
      return SyncPromise.resolve(event);
    }

    return new SyncPromise(resolve => {
      this.walkErrorTree(hint.originalException as Error, this._key)
        .then((linkedErrors: Exception[]) => {
          if (event && event.exception && event.exception.values) {
            event.exception.values = [...linkedErrors, ...event.exception.values];
          }
          resolve(event);
        })
        .then(null, () => {
          resolve(event);
        });
    });
  }
github getsentry / sentry-javascript / packages / core / src / transports / noop.ts View on Github external
public close(_?: number): PromiseLike {
    return SyncPromise.resolve(true);
  }
}