mirror of
https://github.com/status-im/react-native.git
synced 2025-01-28 10:14:49 +00:00
0fe1c7a9ff
Summary: This change makes so that processing stack trace before sending it to packager (see 7dbc805) doesn't modify original frames but creates a copies instead. This is required because after some changes that also have been landed in 0.35, frames that arrive to 'symbolicateStackTrace' are already frozen, so changing 'file' property of the original frame causes symbolication to fail. Closes https://github.com/facebook/react-native/pull/10655 Differential Revision: D4110273 fbshipit-source-id: 0302694b520d83a79c3cb67903038b3f494315f2
59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
* @providesModule symbolicateStackTrace
|
|
* @flow
|
|
*/
|
|
'use strict';
|
|
|
|
const getDevServer = require('getDevServer');
|
|
|
|
const {SourceCode} = require('NativeModules');
|
|
const {fetch} = require('fetch');
|
|
|
|
import type {StackFrame} from 'parseErrorStack';
|
|
|
|
function isSourcedFromDisk(sourcePath: string): boolean {
|
|
return !/^http/.test(sourcePath) && /[\\/]/.test(sourcePath);
|
|
}
|
|
|
|
async function symbolicateStackTrace(stack: Array<StackFrame>): Promise<Array<StackFrame>> {
|
|
const devServer = getDevServer();
|
|
if (!devServer.bundleLoadedFromServer) {
|
|
throw new Error('Bundle was not loaded from the packager');
|
|
}
|
|
|
|
let stackCopy = stack;
|
|
|
|
if (SourceCode.scriptURL) {
|
|
let foundInternalSource: boolean = false;
|
|
stackCopy = stack.map((frame: StackFrame) => {
|
|
// If the sources exist on disk rather than appearing to come from the packager,
|
|
// replace the location with the packager URL until we reach an internal source
|
|
// which does not have a path (no slashes), indicating a switch from within
|
|
// the application to a surrounding debugging environment.
|
|
if (!foundInternalSource && isSourcedFromDisk(frame.file)) {
|
|
// Copy frame into new object and replace 'file' property
|
|
return {...frame, file: SourceCode.scriptURL};
|
|
}
|
|
|
|
foundInternalSource = true;
|
|
return frame;
|
|
});
|
|
}
|
|
|
|
const response = await fetch(devServer.url + 'symbolicate', {
|
|
method: 'POST',
|
|
body: JSON.stringify({stack: stackCopy}),
|
|
});
|
|
const json = await response.json();
|
|
return json.stack;
|
|
}
|
|
|
|
module.exports = symbolicateStackTrace;
|