From a0a34d2a8856fa9611fd8643c16b00e4e3437bfc Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Mon, 19 Apr 2021 11:43:32 -0400 Subject: [PATCH 1/2] Update DevTools Error strings to support GitHub fuzzy search --- .../src/devtools/ProfilerStore.js | 2 +- .../react-devtools-shared/src/devtools/store.js | 14 +++++++------- .../react-devtools-shared/src/devtools/utils.js | 4 ++-- .../devtools/views/Profiler/CommitTreeBuilder.js | 12 ++++-------- .../src/devtools/views/Profiler/utils.js | 8 ++++++-- .../src/inspectedElementMutableSource.js | 4 ++-- packages/react-devtools-shared/src/utils.js | 2 +- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/react-devtools-shared/src/devtools/ProfilerStore.js b/packages/react-devtools-shared/src/devtools/ProfilerStore.js index d1d55bfa3836a..1aa84d2da53f1 100644 --- a/packages/react-devtools-shared/src/devtools/ProfilerStore.js +++ b/packages/react-devtools-shared/src/devtools/ProfilerStore.js @@ -113,7 +113,7 @@ export default class ProfilerStore extends EventEmitter<{| } throw Error( - `Could not find commit data for root "${rootID}" and commit ${commitIndex}`, + `Could not find commit data for root "${rootID}" and commit "${commitIndex}"`, ); } diff --git a/packages/react-devtools-shared/src/devtools/store.js b/packages/react-devtools-shared/src/devtools/store.js index c0083f90a16e4..5fa4bff344da9 100644 --- a/packages/react-devtools-shared/src/devtools/store.js +++ b/packages/react-devtools-shared/src/devtools/store.js @@ -794,7 +794,7 @@ export default class Store extends EventEmitter<{| if (this._idToElement.has(id)) { throw Error( - `Cannot add node ${id} because a node with that id is already in the Store.`, + `Cannot add node "${id}" because a node with that id is already in the Store.`, ); } @@ -857,7 +857,7 @@ export default class Store extends EventEmitter<{| if (!this._idToElement.has(parentID)) { throw Error( - `Cannot add child ${id} to parent ${parentID} because parent node was not found in the Store.`, + `Cannot add child "${id}" to parent "${parentID}" because parent node was not found in the Store.`, ); } @@ -909,7 +909,7 @@ export default class Store extends EventEmitter<{| if (!this._idToElement.has(id)) { throw Error( - `Cannot remove node ${id} because no matching node was found in the Store.`, + `Cannot remove node "${id}" because no matching node was found in the Store.`, ); } @@ -918,7 +918,7 @@ export default class Store extends EventEmitter<{| const element = ((this._idToElement.get(id): any): Element); const {children, ownerID, parentID, weight} = element; if (children.length > 0) { - throw new Error(`Node ${id} was removed before its children.`); + throw new Error(`Node "${id}" was removed before its children.`); } this._idToElement.delete(id); @@ -941,7 +941,7 @@ export default class Store extends EventEmitter<{| parentElement = ((this._idToElement.get(parentID): any): Element); if (parentElement === undefined) { throw Error( - `Cannot remove node ${id} from parent ${parentID} because no matching node was found in the Store.`, + `Cannot remove node "${id}" from parent "${parentID}" because no matching node was found in the Store.`, ); } const index = parentElement.children.indexOf(id); @@ -1002,7 +1002,7 @@ export default class Store extends EventEmitter<{| if (!this._idToElement.has(id)) { throw Error( - `Cannot reorder children for node ${id} because no matching node was found in the Store.`, + `Cannot reorder children for node "${id}" because no matching node was found in the Store.`, ); } @@ -1055,7 +1055,7 @@ export default class Store extends EventEmitter<{| haveErrorsOrWarningsChanged = true; break; default: - throw Error(`Unsupported Bridge operation ${operation}`); + throw Error(`Unsupported Bridge operation "${operation}"`); } } diff --git a/packages/react-devtools-shared/src/devtools/utils.js b/packages/react-devtools-shared/src/devtools/utils.js index 4e71d70bd68f5..35e34b9c8cf42 100644 --- a/packages/react-devtools-shared/src/devtools/utils.js +++ b/packages/react-devtools-shared/src/devtools/utils.js @@ -114,7 +114,7 @@ export function printStore( const element = store.getElementAtIndex(i); if (element == null) { - throw Error(`Could not find element at index ${i}`); + throw Error(`Could not find element at index "${i}"`); } const printedSelectedMarker = printSelectedMarker(i); @@ -131,7 +131,7 @@ export function printStore( // Make sure the pretty-printed test align with the Store's reported number of total rows. if (rootWeight !== store.numElements) { throw Error( - `Inconsistent Store state. Individual root weights (${rootWeight}) do not match total weight (${store.numElements})`, + `Inconsistent Store state. Individual root weights ("${rootWeight}") do not match total weight ("${store.numElements}")`, ); } diff --git a/packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js b/packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js index 85b5c875e4739..e0b5563f4ad26 100644 --- a/packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js +++ b/packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js @@ -116,7 +116,7 @@ export function getCommitTree({ } throw Error( - `getCommitTree(): Unable to reconstruct tree for root "${rootID}" and commit ${commitIndex}`, + `getCommitTree(): Unable to reconstruct tree for root "${rootID}" and commit "${commitIndex}"`, ); } @@ -194,9 +194,7 @@ function updateTree( if (nodes.has(id)) { throw new Error( - 'Commit tree already contains fiber ' + - id + - '. This is a bug in React DevTools.', + `Commit tree already contains fiber "${id}". This is a bug in React DevTools.`, ); } @@ -269,9 +267,7 @@ function updateTree( if (!nodes.has(id)) { throw new Error( - 'Commit tree does not contain fiber ' + - id + - '. This is a bug in React DevTools.', + `Commit tree does not contain fiber "${id}". This is a bug in React DevTools.`, ); } @@ -350,7 +346,7 @@ function updateTree( break; default: - throw Error(`Unsupported Bridge operation ${operation}`); + throw Error(`Unsupported Bridge operation "${operation}"`); } } diff --git a/packages/react-devtools-shared/src/devtools/views/Profiler/utils.js b/packages/react-devtools-shared/src/devtools/views/Profiler/utils.js index 55f7ecb5c1452..cace5aaf2ddb5 100644 --- a/packages/react-devtools-shared/src/devtools/views/Profiler/utils.js +++ b/packages/react-devtools-shared/src/devtools/views/Profiler/utils.js @@ -53,12 +53,16 @@ export function prepareProfilingDataFrontendFromBackendAndStore( }) => { const operations = operationsByRootID.get(rootID); if (operations == null) { - throw Error(`Could not find profiling operations for root ${rootID}`); + throw Error( + `Could not find profiling operations for root "${rootID}"`, + ); } const snapshots = snapshotsByRootID.get(rootID); if (snapshots == null) { - throw Error(`Could not find profiling snapshots for root ${rootID}`); + throw Error( + `Could not find profiling snapshots for root "${rootID}"`, + ); } // Do not filter empty commits from the profiler data! diff --git a/packages/react-devtools-shared/src/inspectedElementMutableSource.js b/packages/react-devtools-shared/src/inspectedElementMutableSource.js index 2504b7932300e..f53ab6398b08d 100644 --- a/packages/react-devtools-shared/src/inspectedElementMutableSource.js +++ b/packages/react-devtools-shared/src/inspectedElementMutableSource.js @@ -77,7 +77,7 @@ export function inspectElement({ // If the Element is still in the Store, we can eagerly remove it from the Map. inspectedElementMap.delete(element); - throw Error(`Element ${id} not found`); + throw Error(`Element "${id}" not found`); case 'full-data': const fullData = ((data: any): InspectElementFullData); @@ -127,6 +127,6 @@ export function inspectElement({ break; } - throw Error(`Unable to inspect element with id ${id}`); + throw Error(`Unable to inspect element with id "${id}"`); }); } diff --git a/packages/react-devtools-shared/src/utils.js b/packages/react-devtools-shared/src/utils.js index be31af5c85ac8..aa60acf06e1f5 100644 --- a/packages/react-devtools-shared/src/utils.js +++ b/packages/react-devtools-shared/src/utils.js @@ -241,7 +241,7 @@ export function printOperationsArray(operations: Array) { ); break; default: - throw Error(`Unsupported Bridge operation ${operation}`); + throw Error(`Unsupported Bridge operation "${operation}"`); } } From 78ed1311806ef92153f23138d41e987633871402 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Mon, 19 Apr 2021 12:39:10 -0400 Subject: [PATCH 2/2] Replace multiple ids in error message --- .../src/devtools/views/ErrorBoundary/githubAPI.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-devtools-shared/src/devtools/views/ErrorBoundary/githubAPI.js b/packages/react-devtools-shared/src/devtools/views/ErrorBoundary/githubAPI.js index e8392d89799ae..571940e79b63f 100644 --- a/packages/react-devtools-shared/src/devtools/views/ErrorBoundary/githubAPI.js +++ b/packages/react-devtools-shared/src/devtools/views/ErrorBoundary/githubAPI.js @@ -18,7 +18,7 @@ export async function searchGitHubIssues( message: string, ): Promise { // Remove Fiber IDs from error message (as those will be unique). - message = message.replace(/"[0-9]+"/, ''); + message = message.replace(/"[0-9]+"/g, ''); const filters = [ 'in:title',