[Flight] Compute better I/O description for exotic types#34650
Merged
eps1lon merged 1 commit intofacebook:mainfrom Sep 29, 2025
Conversation
|
Comparing: 319a786...9d47086 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) |
sebmarkbage
approved these changes
Sep 29, 2025
sebmarkbage
reviewed
Sep 29, 2025
Comment on lines
10
to
72
| export function getIODescription(value: mixed): string { | ||
| if (!__DEV__) { | ||
| return ''; | ||
| } | ||
| try { | ||
| switch (typeof value) { | ||
| case 'object': | ||
| // Test the object for a bunch of common property names that are useful identifiers. | ||
| // While we only have the return value here, it should ideally be a name that | ||
| // describes the arguments requested. | ||
| if (value === null) { | ||
| return ''; | ||
| } else if (value instanceof Error) { | ||
| // eslint-disable-next-line react-internal/safe-string-coercion | ||
| return String(value.message); | ||
| } else if (typeof value.url === 'string') { | ||
| return value.url; | ||
| } else if (typeof value.href === 'string') { | ||
| return value.href; | ||
| } else if (typeof value.src === 'string') { | ||
| return value.src; | ||
| } else if (typeof value.currentSrc === 'string') { | ||
| return value.currentSrc; | ||
| } else if (typeof value.command === 'string') { | ||
| return value.command; | ||
| } else if ( | ||
| typeof value.request === 'object' && | ||
| value.request !== null && | ||
| typeof value.request.url === 'string' | ||
| ) { | ||
| return value.request.url; | ||
| } else if ( | ||
| typeof value.response === 'object' && | ||
| value.response !== null && | ||
| typeof value.response.url === 'string' | ||
| ) { | ||
| return value.response.url; | ||
| } else if ( | ||
| typeof value.id === 'string' || | ||
| typeof value.id === 'number' || | ||
| typeof value.id === 'bigint' | ||
| ) { | ||
| // eslint-disable-next-line react-internal/safe-string-coercion | ||
| return String(value.id); | ||
| } else if (typeof value.name === 'string') { | ||
| return value.name; | ||
| } else { | ||
| const str = value.toString(); | ||
| if (str.startWith('[object ') || str.length < 5 || str.length > 500) { | ||
| if ( | ||
| str.startsWith('[object ') || | ||
| str.length < 5 || | ||
| str.length > 500 | ||
| ) { | ||
| // This is probably not a useful description. | ||
| return ''; | ||
| } | ||
| return str; | ||
| } | ||
| case 'string': | ||
| if (value.length < 5 || value.length > 500) { | ||
| return ''; | ||
| } | ||
| return value; |
Contributor
There was a problem hiding this comment.
This whole thing is inside a try/catch so how could you have gotten a crash? Wouldn't it just be empty string?
Contributor
There was a problem hiding this comment.
(Also the new GitHub UI is very buggy. This is not the line I commented on.
Collaborator
Author
There was a problem hiding this comment.
I didn't see a crash but me stepping through with pausing on caught exceptions. Didn't see the try-catch higher up.
Collaborator
Author
There was a problem hiding this comment.
Updated title and PR desc
This was referenced Sep 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Could also affect DevTools. Bumped into this with "TypeError: str.startWith is not a function". Stricter types revealed some more potential misses.