Java Code Examples for com.facebook.react.devsupport.StackTraceHelper.StackFrame

The following are top voted examples for showing how to use com.facebook.react.devsupport.StackTraceHelper.StackFrame. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: ReactNativeSignatureExample   File: DevSupportManagerImpl.java   Source Code and License 6 votes vote down vote up
private void showNewError(
    final String message,
    final StackFrame[] stack,
    final int errorCookie) {
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          if (mRedBoxDialog == null) {
            mRedBoxDialog = new RedBoxDialog(mApplicationContext, DevSupportManagerImpl.this);
            mRedBoxDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
          }
          if (mRedBoxDialog.isShowing()) {
            // Sometimes errors cause multiple errors to be thrown in JS in quick succession. Only
            // show the first and most actionable one.
            return;
          }
          mRedBoxDialog.setExceptionDetails(message, stack);
          mRedBoxDialog.setErrorCookie(errorCookie);
          mRedBoxDialog.show();
        }
      });
}
 
Example 2
Project: ReactNativeSignatureExample   File: RedBoxDialog.java   Source Code and License 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
  if (position == 0) {
    TextView title = convertView != null
        ? (TextView) convertView
        : (TextView) LayoutInflater.from(parent.getContext())
            .inflate(R.layout.redbox_item_title, parent, false);
    title.setText(mTitle);
    return title;
  } else {
    if (convertView == null) {
      convertView = LayoutInflater.from(parent.getContext())
          .inflate(R.layout.redbox_item_frame, parent, false);
      convertView.setTag(new FrameViewHolder(convertView));
    }
    StackFrame frame = mStack[position - 1];
    FrameViewHolder holder = (FrameViewHolder) convertView.getTag();
    holder.mMethodView.setText(frame.getMethod());
    holder.mFileView.setText(frame.getFileName() + ":" + frame.getLine());
    return convertView;
  }
}
 
Example 3
Project: ReactNativeSignatureExample   File: RedBoxDialog.java   Source Code and License 6 votes vote down vote up
@Override
protected Void doInBackground(StackFrame... stackFrames) {
  try {
    String openStackFrameUrl =
        Uri.parse(mDevSupportManager.getSourceUrl()).buildUpon()
            .path("/open-stack-frame")
            .query(null)
            .build()
            .toString();
    OkHttpClient client = new OkHttpClient();
    for (StackFrame frame: stackFrames) {
      String payload = stackFrameToJson(frame).toString();
      RequestBody body = RequestBody.create(JSON, payload);
      Request request = new Request.Builder().url(openStackFrameUrl).post(body).build();
      client.newCall(request).execute();
    }
  } catch (Exception e) {
    FLog.e(ReactConstants.TAG, "Could not open stack frame", e);
  }
  return null;
}
 
Example 4
Project: react-native-ibeacon-android   File: DevSupportManagerImpl.java   Source Code and License 6 votes vote down vote up
private void showNewError(
    final String message,
    final StackFrame[] stack,
    final int errorCookie) {
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          if (mRedBoxDialog == null) {
            mRedBoxDialog = new RedBoxDialog(mApplicationContext, DevSupportManagerImpl.this);
            mRedBoxDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
          }
          if (mRedBoxDialog.isShowing()) {
            // Sometimes errors cause multiple errors to be thrown in JS in quick succession. Only
            // show the first and most actionable one.
            return;
          }
          mRedBoxDialog.setExceptionDetails(message, stack);
          mRedBoxDialog.setErrorCookie(errorCookie);
          mRedBoxDialog.show();
        }
      });
}
 
Example 5
Project: react-native-ibeacon-android   File: RedBoxDialog.java   Source Code and License 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
  if (position == 0) {
    TextView title = convertView != null
        ? (TextView) convertView
        : (TextView) LayoutInflater.from(parent.getContext())
            .inflate(R.layout.redbox_item_title, parent, false);
    title.setText(mTitle);
    return title;
  } else {
    if (convertView == null) {
      convertView = LayoutInflater.from(parent.getContext())
          .inflate(R.layout.redbox_item_frame, parent, false);
      convertView.setTag(new FrameViewHolder(convertView));
    }
    StackFrame frame = mStack[position - 1];
    FrameViewHolder holder = (FrameViewHolder) convertView.getTag();
    holder.mMethodView.setText(frame.getMethod());
    holder.mFileView.setText(frame.getFileName() + ":" + frame.getLine());
    return convertView;
  }
}
 
Example 6
Project: react-native-ibeacon-android   File: RedBoxDialog.java   Source Code and License 6 votes vote down vote up
@Override
protected Void doInBackground(StackFrame... stackFrames) {
  try {
    String openStackFrameUrl =
        Uri.parse(mDevSupportManager.getSourceUrl()).buildUpon()
            .path("/open-stack-frame")
            .query(null)
            .build()
            .toString();
    OkHttpClient client = new OkHttpClient();
    for (StackFrame frame: stackFrames) {
      String payload = stackFrameToJson(frame).toString();
      RequestBody body = RequestBody.create(JSON, payload);
      Request request = new Request.Builder().url(openStackFrameUrl).post(body).build();
      client.newCall(request).execute();
    }
  } catch (Exception e) {
    FLog.e(ReactConstants.TAG, "Could not open stack frame", e);
  }
  return null;
}
 
Example 7
Project: react-native-box-loaders   File: DevSupportManagerImpl.java   Source Code and License 6 votes vote down vote up
private void showNewError(
    final String message,
    final StackFrame[] stack,
    final int errorCookie) {
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          if (mRedBoxDialog == null) {
            mRedBoxDialog = new RedBoxDialog(mApplicationContext, DevSupportManagerImpl.this);
            mRedBoxDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
          }
          if (mRedBoxDialog.isShowing()) {
            // Sometimes errors cause multiple errors to be thrown in JS in quick succession. Only
            // show the first and most actionable one.
            return;
          }
          mRedBoxDialog.setExceptionDetails(message, stack);
          mRedBoxDialog.setErrorCookie(errorCookie);
          mRedBoxDialog.show();
        }
      });
}
 
Example 8
Project: react-native-box-loaders   File: RedBoxDialog.java   Source Code and License 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
  if (position == 0) {
    TextView title = convertView != null
        ? (TextView) convertView
        : (TextView) LayoutInflater.from(parent.getContext())
            .inflate(R.layout.redbox_item_title, parent, false);
    title.setText(mTitle);
    return title;
  } else {
    if (convertView == null) {
      convertView = LayoutInflater.from(parent.getContext())
          .inflate(R.layout.redbox_item_frame, parent, false);
      convertView.setTag(new FrameViewHolder(convertView));
    }
    StackFrame frame = mStack[position - 1];
    FrameViewHolder holder = (FrameViewHolder) convertView.getTag();
    holder.mMethodView.setText(frame.getMethod());
    final int column = frame.getColumn();
    final String columnString = column < 0 ? "" : ":" + column;
    holder.mFileView.setText(frame.getFileName() + ":" + frame.getLine() + columnString);
    return convertView;
  }
}
 
Example 9
Project: react-native-box-loaders   File: RedBoxDialog.java   Source Code and License 6 votes vote down vote up
@Override
protected Void doInBackground(StackFrame... stackFrames) {
  try {
    String openStackFrameUrl =
        Uri.parse(mDevSupportManager.getSourceUrl()).buildUpon()
            .path("/open-stack-frame")
            .query(null)
            .build()
            .toString();
    OkHttpClient client = new OkHttpClient();
    for (StackFrame frame: stackFrames) {
      String payload = stackFrameToJson(frame).toString();
      RequestBody body = RequestBody.create(JSON, payload);
      Request request = new Request.Builder().url(openStackFrameUrl).post(body).build();
      client.newCall(request).execute();
    }
  } catch (Exception e) {
    FLog.e(ReactConstants.TAG, "Could not open stack frame", e);
  }
  return null;
}
 
Example 10
Project: Ironman   File: DevSupportManagerImpl.java   Source Code and License 6 votes vote down vote up
@Override
public void handleException(Exception e) {
  if (mIsDevSupportEnabled) {
    if (e instanceof JSException) {
      FLog.e(ReactConstants.TAG, "Exception in native call from JS", e);
      // TODO #11638796: convert the stack into something useful
      showNewError(
          e.getMessage() + "\n\n" + ((JSException) e).getStack(),
          new StackFrame[] {},
          JSEXCEPTION_ERROR_COOKIE,
          ErrorType.JS);
    } else {
      showNewJavaError(e.getMessage(), e);
    }
  } else {
    mDefaultNativeModuleCallExceptionHandler.handleException(e);
  }
}
 
Example 11
Project: Ironman   File: RedBoxDialog.java   Source Code and License 6 votes vote down vote up
@Override
public void onClick(View view) {
  if (mRedBoxHandler == null || !mRedBoxHandler.isReportEnabled() || isReporting) {
    return;
  }
  isReporting = true;
  Assertions.assertNotNull(mReportTextView).setText("Reporting...");
  Assertions.assertNotNull(mReportTextView).setVisibility(View.VISIBLE);
  Assertions.assertNotNull(mLoadingIndicator).setVisibility(View.VISIBLE);
  Assertions.assertNotNull(mLineSeparator).setVisibility(View.VISIBLE);
  Assertions.assertNotNull(mReportButton).setEnabled(false);

  String title = Assertions.assertNotNull(mDevSupportManager.getLastErrorTitle());
  StackFrame[] stack = Assertions.assertNotNull(mDevSupportManager.getLastErrorStack());
  String sourceUrl = mDevSupportManager.getSourceUrl();

  mRedBoxHandler.reportRedbox(
    title,
    stack,
    sourceUrl,
    Assertions.assertNotNull(mReportCompletedListener));
}
 
Example 12
Project: Ironman   File: RedBoxDialog.java   Source Code and License 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
  if (position == 0) {
    TextView title = convertView != null
        ? (TextView) convertView
        : (TextView) LayoutInflater.from(parent.getContext())
            .inflate(R.layout.redbox_item_title, parent, false);
    title.setText(mTitle);
    return title;
  } else {
    if (convertView == null) {
      convertView = LayoutInflater.from(parent.getContext())
          .inflate(R.layout.redbox_item_frame, parent, false);
      convertView.setTag(new FrameViewHolder(convertView));
    }
    StackFrame frame = mStack[position - 1];
    FrameViewHolder holder = (FrameViewHolder) convertView.getTag();
    holder.mMethodView.setText(frame.getMethod());
    holder.mFileView.setText(StackTraceHelper.formatFrameSource(frame));
    return convertView;
  }
}
 
Example 13
Project: Ironman   File: RedBoxDialog.java   Source Code and License 6 votes vote down vote up
@Override
protected Void doInBackground(StackFrame... stackFrames) {
  try {
    String openStackFrameUrl =
        Uri.parse(mDevSupportManager.getSourceUrl()).buildUpon()
            .path("/open-stack-frame")
            .query(null)
            .build()
            .toString();
    OkHttpClient client = new OkHttpClient();
    for (StackFrame frame: stackFrames) {
      String payload = stackFrameToJson(frame).toString();
      RequestBody body = RequestBody.create(JSON, payload);
      Request request = new Request.Builder().url(openStackFrameUrl).post(body).build();
      client.newCall(request).execute();
    }
  } catch (Exception e) {
    FLog.e(ReactConstants.TAG, "Could not open stack frame", e);
  }
  return null;
}
 
Example 14
Project: ReactNativeSignatureExample   File: RedBoxDialog.java   Source Code and License 5 votes vote down vote up
private static JSONObject stackFrameToJson(StackFrame frame) {
  return new JSONObject(
      MapBuilder.of(
          "file", frame.getFile(),
          "methodName", frame.getMethod(),
          "lineNumber", frame.getLine(),
          "column", frame.getColumn()
      ));
}
 
Example 15
Project: react-native-ibeacon-android   File: RedBoxDialog.java   Source Code and License 5 votes vote down vote up
private static JSONObject stackFrameToJson(StackFrame frame) {
  return new JSONObject(
      MapBuilder.of(
          "file", frame.getFile(),
          "methodName", frame.getMethod(),
          "lineNumber", frame.getLine(),
          "column", frame.getColumn()
      ));
}
 
Example 16
Project: react-native-box-loaders   File: RedBoxDialog.java   Source Code and License 5 votes vote down vote up
private static JSONObject stackFrameToJson(StackFrame frame) {
  return new JSONObject(
      MapBuilder.of(
          "file", frame.getFile(),
          "methodName", frame.getMethod(),
          "lineNumber", frame.getLine(),
          "column", frame.getColumn()
      ));
}
 
Example 17
Project: Ironman   File: DevSupportManagerImpl.java   Source Code and License 5 votes vote down vote up
@Override
public void updateJSError(
    final String message,
    final ReadableArray details,
    final int errorCookie) {
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          // Since we only show the first JS error in a succession of JS errors, make sure we only
          // update the error message for that error message. This assumes that updateJSError
          // belongs to the most recent showNewJSError
          if (mRedBoxDialog == null ||
              !mRedBoxDialog.isShowing() ||
              errorCookie != mLastErrorCookie) {
            return;
          }
          StackFrame[] stack = StackTraceHelper.convertJsStackTrace(details);
          mRedBoxDialog.setExceptionDetails(message, stack);
          updateLastErrorInfo(message, stack, errorCookie, ErrorType.JS);
          // JS errors are reported here after source mapping.
          if (mRedBoxHandler != null) {
            mRedBoxHandler.handleRedbox(message, stack, RedBoxHandler.ErrorType.JS);
            mRedBoxDialog.resetReporting(true);
          }
          mRedBoxDialog.show();
        }
      });
}
 
Example 18
Project: Ironman   File: DevSupportManagerImpl.java   Source Code and License 5 votes vote down vote up
private void showNewError(
    final String message,
    final StackFrame[] stack,
    final int errorCookie,
    final ErrorType errorType) {
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          if (mRedBoxDialog == null) {
            mRedBoxDialog = new RedBoxDialog(mApplicationContext, DevSupportManagerImpl.this, mRedBoxHandler);
            mRedBoxDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
          }
          if (mRedBoxDialog.isShowing()) {
            // Sometimes errors cause multiple errors to be thrown in JS in quick succession. Only
            // show the first and most actionable one.
            return;
          }
          mRedBoxDialog.setExceptionDetails(message, stack);
          updateLastErrorInfo(message, stack, errorCookie, errorType);
          // Only report native errors here. JS errors are reported
          // inside {@link #updateJSError} after source mapping.
          if (mRedBoxHandler != null && errorType == ErrorType.NATIVE) {
            mRedBoxHandler.handleRedbox(message, stack, RedBoxHandler.ErrorType.NATIVE);
            mRedBoxDialog.resetReporting(true);
          } else {
            mRedBoxDialog.resetReporting(false);
          }
          mRedBoxDialog.show();
        }
      });
}
 
Example 19
Project: Ironman   File: DevSupportManagerImpl.java   Source Code and License 5 votes vote down vote up
private void updateLastErrorInfo(
    final String message,
    final StackFrame[] stack,
    final int errorCookie,
    final ErrorType errorType) {
  mLastErrorTitle = message;
  mLastErrorStack = stack;
  mLastErrorCookie = errorCookie;
  mLastErrorType = errorType;
}
 
Example 20
Project: Ironman   File: RedBoxDialog.java   Source Code and License 5 votes vote down vote up
private static JSONObject stackFrameToJson(StackFrame frame) {
  return new JSONObject(
      MapBuilder.of(
          "file", frame.getFile(),
          "methodName", frame.getMethod(),
          "lineNumber", frame.getLine(),
          "column", frame.getColumn()
      ));
}
 
Example 21
Project: ReactNativeSignatureExample   File: RedBoxDialog.java   Source Code and License 4 votes vote down vote up
public StackAdapter(String title, StackFrame[] stack) {
  mTitle = title;
  mStack = stack;
}
 
Example 22
Project: ReactNativeSignatureExample   File: RedBoxDialog.java   Source Code and License 4 votes vote down vote up
public void setExceptionDetails(String title, StackFrame[] stack) {
  mStackView.setAdapter(new StackAdapter(title, stack));
}
 
Example 23
Project: ReactNativeSignatureExample   File: RedBoxDialog.java   Source Code and License 4 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  new OpenStackFrameTask(mDevSupportManager).executeOnExecutor(
      AsyncTask.THREAD_POOL_EXECUTOR,
      (StackFrame) mStackView.getAdapter().getItem(position));
}
 
Example 24
Project: react-native-ibeacon-android   File: RedBoxDialog.java   Source Code and License 4 votes vote down vote up
public StackAdapter(String title, StackFrame[] stack) {
  mTitle = title;
  mStack = stack;
}
 
Example 25
Project: react-native-ibeacon-android   File: RedBoxDialog.java   Source Code and License 4 votes vote down vote up
public void setExceptionDetails(String title, StackFrame[] stack) {
  mStackView.setAdapter(new StackAdapter(title, stack));
}
 
Example 26
Project: react-native-ibeacon-android   File: RedBoxDialog.java   Source Code and License 4 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  new OpenStackFrameTask(mDevSupportManager).executeOnExecutor(
      AsyncTask.THREAD_POOL_EXECUTOR,
      (StackFrame) mStackView.getAdapter().getItem(position));
}
 
Example 27
Project: react-native-box-loaders   File: RedBoxDialog.java   Source Code and License 4 votes vote down vote up
public StackAdapter(String title, StackFrame[] stack) {
  mTitle = title;
  mStack = stack;
}
 
Example 28
Project: react-native-box-loaders   File: RedBoxDialog.java   Source Code and License 4 votes vote down vote up
public void setExceptionDetails(String title, StackFrame[] stack) {
  mStackView.setAdapter(new StackAdapter(title, stack));
}
 
Example 29
Project: react-native-box-loaders   File: RedBoxDialog.java   Source Code and License 4 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  new OpenStackFrameTask(mDevSupportManager).executeOnExecutor(
      AsyncTask.THREAD_POOL_EXECUTOR,
      (StackFrame) mStackView.getAdapter().getItem(position));
}
 
Example 30
Project: Ironman   File: DevSupportManagerImpl.java   Source Code and License 4 votes vote down vote up
@Override
public @Nullable StackFrame[] getLastErrorStack() {
  return mLastErrorStack;
}
 
Example 31
Project: Ironman   File: RedBoxHandler.java   Source Code and License 4 votes vote down vote up
/**
 * Report the information from the redbox and set up a callback listener.
 */
void reportRedbox(
  String title,
  StackFrame[] stack,
  String sourceUrl,
  ReportCompletedListener reportCompletedListener);
 
Example 32
Project: Ironman   File: RedBoxDialog.java   Source Code and License 4 votes vote down vote up
public StackAdapter(String title, StackFrame[] stack) {
  mTitle = title;
  mStack = stack;
}
 
Example 33
Project: Ironman   File: RedBoxDialog.java   Source Code and License 4 votes vote down vote up
public void setExceptionDetails(String title, StackFrame[] stack) {
  mStackView.setAdapter(new StackAdapter(title, stack));
}
 
Example 34
Project: Ironman   File: RedBoxDialog.java   Source Code and License 4 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  new OpenStackFrameTask(mDevSupportManager).executeOnExecutor(
      AsyncTask.THREAD_POOL_EXECUTOR,
      (StackFrame) mStackView.getAdapter().getItem(position));
}
 
Example 35
Project: Ironman   File: DisabledDevSupportManager.java   Source Code and License 4 votes vote down vote up
@Override
public @Nullable StackFrame[] getLastErrorStack() {
  return null;
}
 
Example 36
Project: Ironman   File: RedBoxHandler.java   Source Code and License 2 votes vote down vote up
/**
 * Handle the information from the redbox.
 */
void handleRedbox(String title, StackFrame[] stack, ErrorType errorType);
 
Example 37
Project: Ironman   File: DevSupportManager.java   Source Code and License votes vote down vote up
@Nullable StackFrame[] getLastErrorStack();