Skip to content

Commit 2774208

Browse files
authoredJun 10, 2024
Remove Warning: prefix and toString on console Arguments (#29839)
Basically make `console.error` and `console.warn` behave like normal - when a component stack isn't appended. I need this because I need to be able to print rich logs with the component stack option and to be able to disable instrumentation completely in `console.createTask` environments that don't need it. Currently we can't print logs with richer objects because they're toString:ed first. In practice, pretty much all arguments we log are already toString:ed so it's not necessary anyway. Some might be like a number. So it would only be a problem if some environment can't handle proper consoles but then it's up to that environment to toString it before logging. The `Warning: ` prefix is historic and is both noisy and confusing. It's mostly unnecessary since the UI surrounding `console.error` and `console.warn` tend to have visual treatment around it anyway. However, it's actively misleading when `console.error` gets prefixed with a Warning that we consider an error level. There's an argument to be made that some of our `console.error` don't make the bar for an error but then the argument is to downgrade each of those to `console.warn` - not to brand all our actual error logging with `Warning: `. Apparently something needs to change in React Native before landing this because it depends on the prefix somehow which probably doesn't make sense already.
1 parent d172bda commit 2774208

File tree

77 files changed

+397
-418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+397
-418
lines changed
 

‎packages/internal-test-utils/shouldIgnoreConsoleError.js

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ module.exports = function shouldIgnoreConsoleError(format, args) {
77
args[0] != null &&
88
((typeof args[0] === 'object' &&
99
typeof args[0].message === 'string' &&
10+
// This specific log has the same signature as error logging.
11+
// The trick is to get rid of this whole file.
12+
!format.includes('Failed to serialize an action') &&
1013
typeof args[0].stack === 'string') ||
1114
(typeof args[0] === 'string' &&
1215
args[0].indexOf('An error occurred in ') === 0))

‎packages/react-cache/src/__tests__/ReactCacheOld-test.internal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ describe('ReactCache', () => {
182182
await waitForAll(['App', 'Loading...']);
183183
}).toErrorDev([
184184
'Invalid key type. Expected a string, number, symbol, or ' +
185-
'boolean, but instead received: Hi,100\n\n' +
185+
"boolean, but instead received: [ 'Hi', 100 ]\n\n" +
186186
'To use non-primitive values as keys, you must pass a hash ' +
187187
'function as the second argument to createResource().',
188188
]);

0 commit comments

Comments
 (0)