當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript SyncPromise.resolve方法代碼示例

本文整理匯總了TypeScript中@sentry/utils.SyncPromise.resolve方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript SyncPromise.resolve方法的具體用法?TypeScript SyncPromise.resolve怎麽用?TypeScript SyncPromise.resolve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@sentry/utils.SyncPromise的用法示例。


在下文中一共展示了SyncPromise.resolve方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: parseStack

export function parseStack(stack: stacktrace.StackFrame[], options?: NodeOptions): SyncPromise<StackFrame[]> {
  const filesToRead: string[] = [];

  const linesOfContext =
    options && options.frameContextLines !== undefined ? options.frameContextLines : DEFAULT_LINES_OF_CONTEXT;

  const frames: StackFrame[] = stack.map(frame => {
    const parsedFrame: StackFrame = {
      colno: frame.columnNumber,
      filename: frame.fileName || '',
      function: getFunction(frame),
      lineno: frame.lineNumber,
    };

    const isInternal =
      frame.native ||
      (parsedFrame.filename &&
        !parsedFrame.filename.startsWith('/') &&
        !parsedFrame.filename.startsWith('.') &&
        parsedFrame.filename.indexOf(':\\') !== 1);

    // in_app is all that's not an internal Node function or a module within node_modules
    // note that isNative appears to return true even for node core libraries
    // see https://github.com/getsentry/raven-node/issues/176
    parsedFrame.in_app =
      !isInternal && parsedFrame.filename !== undefined && !parsedFrame.filename.includes('node_modules/');

    // Extract a module name based on the filename
    if (parsedFrame.filename) {
      parsedFrame.module = getModule(parsedFrame.filename);

      if (!isInternal && linesOfContext > 0) {
        filesToRead.push(parsedFrame.filename);
      }
    }

    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);
  }
}
開發者ID:getsentry,項目名稱:raven-js,代碼行數:52,代碼來源:parsers.ts

示例2: addExceptionTypeValue

 return this.eventFromMessage(stringException, undefined, hint).then(messageEvent => {
   addExceptionTypeValue(messageEvent, `${stringException}`, undefined, {
     handled: true,
     synthetic: true,
     type: 'generic',
   });
   messageEvent.level = Severity.Error;
   return SyncPromise.resolve(this._buildEvent(messageEvent, hint));
 });
開發者ID:getsentry,項目名稱:raven-js,代碼行數:9,代碼來源:backend.ts

示例3: eventFromException

 public eventFromException(exception: any): SyncPromise<Event> {
   return SyncPromise.resolve({
     exception: {
       values: [
         {
           type: exception.name,
           value: exception.message,
         },
       ],
     },
   });
 }
開發者ID:getsentry,項目名稱:raven-js,代碼行數:12,代碼來源:backend.ts

示例4: readSourceFiles

/**
 * This function reads file contents and caches them in a global LRU cache.
 * Returns a Promise filepath => content array for all files that we were able to read.
 *
 * @param filenames Array of filepaths to read content from.
 */
function readSourceFiles(filenames: string[]): SyncPromise<{ [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
      if (cache !== undefined) {
        // If it's not null (which means we found a file and have a content)
        // we set the content and return it later.
        if (cache !== null) {
          sourceFiles[filename] = cache;
        }
        count++;
        // In any case we want to skip here then since we have a content already or we couldn't
        // read the file and don't want to try again.
        if (count === filenames.length) {
          resolve(sourceFiles);
        }
        continue;
      }

      readFile(filename, (err: Error | null, data: Buffer) => {
        const content = err ? null : data.toString();
        sourceFiles[filename] = content;

        // We always want to set the cache, even to null which means there was an error reading the file.
        // We do not want to try to read the file again.
        FILE_CONTENT_CACHE.set(filename, content);
        count++;
        if (count === filenames.length) {
          resolve(sourceFiles);
        }
      });
    }
  });
}
開發者ID:getsentry,項目名稱:raven-js,代碼行數:56,代碼來源:parsers.ts

示例5: eventFromMessage

  /**
   * @inheritDoc
   */
  public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): SyncPromise<Event> {
    const event: Event = {
      event_id: hint && hint.event_id,
      level,
      message,
    };

    if (this._options.attachStacktrace && hint && hint.syntheticException) {
      const stacktrace = _computeStackTrace(hint.syntheticException);
      const frames = prepareFramesForEvent(stacktrace.stack);
      event.stacktrace = {
        frames,
      };
    }

    return SyncPromise.resolve(event);
  }
開發者ID:getsentry,項目名稱:raven-js,代碼行數:20,代碼來源:backend.ts

示例6: eventFromException

  /**
   * @inheritDoc
   */
  public eventFromException(exception: any, hint?: EventHint): SyncPromise<Event> {
    let event: Event;

    if (isErrorEvent(exception as ErrorEvent) && (exception as ErrorEvent).error) {
      // If it is an ErrorEvent with `error` property, extract it to get actual Error
      const errorEvent = exception as ErrorEvent;
      exception = errorEvent.error; // tslint:disable-line:no-parameter-reassignment
      event = eventFromStacktrace(_computeStackTrace(exception as Error));
      return SyncPromise.resolve(this._buildEvent(event, hint));
    }
    if (isDOMError(exception as DOMError) || isDOMException(exception as DOMException)) {
      // If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers)
      // then we just extract the name and message, as they don't provide anything else
      // https://developer.mozilla.org/en-US/docs/Web/API/DOMError
      // https://developer.mozilla.org/en-US/docs/Web/API/DOMException
      const domException = exception as DOMException;
      const name = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException');
      const message = domException.message ? `${name}: ${domException.message}` : name;

      return this.eventFromMessage(message, Severity.Error, hint).then(messageEvent => {
        addExceptionTypeValue(messageEvent, message);
        return SyncPromise.resolve(this._buildEvent(messageEvent, hint));
      });
    }
    if (isError(exception as Error)) {
      // we have a real Error object, do nothing
      event = eventFromStacktrace(_computeStackTrace(exception as Error));
      return SyncPromise.resolve(this._buildEvent(event, hint));
    }
    if (isPlainObject(exception as {}) && hint && hint.syntheticException) {
      // If it is plain Object, serialize it manually and extract options
      // This will allow us to group events based on top-level keys
      // which is much better than creating new group when any key/value change
      const objectException = exception as {};
      event = eventFromPlainObject(objectException, hint.syntheticException);
      addExceptionTypeValue(event, 'Custom Object', undefined, {
        handled: true,
        synthetic: true,
        type: 'generic',
      });
      event.level = Severity.Error;
      return SyncPromise.resolve(this._buildEvent(event, hint));
    }

    // If none of previous checks were valid, then it means that
    // it's not a DOMError/DOMException
    // it's not a plain Object
    // it's not a valid ErrorEvent (one with an error property)
    // it's not an Error
    // So bail out and capture it as a simple message:
    const stringException = exception as string;
    return this.eventFromMessage(stringException, undefined, hint).then(messageEvent => {
      addExceptionTypeValue(messageEvent, `${stringException}`, undefined, {
        handled: true,
        synthetic: true,
        type: 'generic',
      });
      messageEvent.level = Severity.Error;
      return SyncPromise.resolve(this._buildEvent(messageEvent, hint));
    });
  }
開發者ID:getsentry,項目名稱:raven-js,代碼行數:64,代碼來源:backend.ts

示例7: eventFromMessage

 public eventFromMessage(message: string): SyncPromise<Event> {
   return SyncPromise.resolve({ message });
 }
開發者ID:getsentry,項目名稱:raven-js,代碼行數:3,代碼來源:backend.ts


注:本文中的@sentry/utils.SyncPromise.resolve方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。