Catch DataExportError from shareFlipperData

Summary:
There was a bug where if the `shareFlipperData` returned an `error` with a status code of less than 400 then it will be ignored. If the status code was of greater than or equal to 400 then `shareFlipperData` throws an error and it is caught and logged appropriately.

This diff fixes the above issue where if the return type from shareFlipperData is of type DataExportError then it is checked and not ignored. Also this fixes an issue where if DataExportError happens the loader is replaced with an error message.

Basically the bug mentioned here, T55169042. Also this diff logs the metadata of result, so that we can debug the exact error through scuba.

Reviewed By: mweststrate

Differential Revision: D20450159

fbshipit-source-id: 95b1f384886c16fe444ae0cd6f6d9b2251c29005
This commit is contained in:
Pritesh Nandgaonkar
2020-03-16 05:20:11 -07:00
committed by Facebook GitHub Bot
parent 0e920e8558
commit 148f90de7f

View File

@@ -131,12 +131,17 @@ export default class ShareSheetExportUrl extends Component<Props, State> {
const uploadMarker = `${EXPORT_FLIPPER_TRACE_EVENT}:upload`; const uploadMarker = `${EXPORT_FLIPPER_TRACE_EVENT}:upload`;
performance.mark(uploadMarker); performance.mark(uploadMarker);
statusUpdate('Uploading Flipper Trace...'); statusUpdate('Uploading Flipper Trace...');
// TODO(T55169042): Implement error handling. Result is not tested
// its result type right now, causing the upload indicator to stall forever.
const result = await reportPlatformFailures( const result = await reportPlatformFailures(
shareFlipperData(serializedString), shareFlipperData(serializedString),
`${SHARE_FLIPPER_TRACE_EVENT}`, `${SHARE_FLIPPER_TRACE_EVENT}`,
); );
if ((result as DataExportError).error != undefined) {
const res = result as DataExportError;
const err = new Error(res.error);
err.stack = res.stacktrace;
throw err;
}
getLogger().trackTimeSince(uploadMarker, uploadMarker, { getLogger().trackTimeSince(uploadMarker, uploadMarker, {
plugins: this.store.getState().plugins.selectedPlugins, plugins: this.store.getState().plugins.selectedPlugins,
}); });
@@ -153,23 +158,21 @@ export default class ShareSheetExportUrl extends Component<Props, State> {
this.store.dispatch(resetSupportFormV2State()); this.store.dispatch(resetSupportFormV2State());
this.props.logger.trackTimeSince(mark, 'export:url-success'); this.props.logger.trackTimeSince(mark, 'export:url-success');
} catch (e) { } catch (e) {
if (!this.state.runInBackground) {
const result: DataExportError = { const result: DataExportError = {
error_class: 'EXPORT_ERROR', error_class: 'EXPORT_ERROR',
error: '', error: e,
stacktrace: '', stacktrace: '',
}; };
if (!this.state.runInBackground) {
if (e instanceof Error) { if (e instanceof Error) {
result.error = e.message; result.error = e.message;
result.stacktrace = e.stack || ''; result.stacktrace = e.stack || '';
} else {
result.error = e;
} }
// Show the error in UI.
this.setState({result}); this.setState({result});
} }
this.store.dispatch(unsetShare()); this.store.dispatch(unsetShare());
this.props.logger.trackTimeSince(mark, 'export:url-error'); this.props.logger.trackTimeSince(mark, 'export:url-error', result);
throw e; throw e;
} }
} }
@@ -221,7 +224,7 @@ export default class ShareSheetExportUrl extends Component<Props, State> {
render() { render() {
const {result, statusUpdate, errorArray} = this.state; const {result, statusUpdate, errorArray} = this.state;
if (!result || !(result as DataExportResult).flipperUrl) { if (!result) {
return this.renderPending(statusUpdate); return this.renderPending(statusUpdate);
} }