Skip to content

Conversation

@pablomatiasgomez
Copy link
Contributor

The utility to get the original function name of a given token is slightly incorrect.
The mappings included in the map file, for whatever reason are 1-based indexed for the lines, and 0-based for the columns.

Given that we were doing the lookup based on both 0-based indexes, sometimes the lookup was incorrect as we are pointing to line before, and in cases where the token is the very first line of the function, it may return an invalid function name (only when the column ends up being also before the function keyword)

I added a test case based on the testdata that we have today that points to the throw token of the module.js file, which is before the function in terms of the column, and that showed the error.

Also, here we can see that facebook uses 1-based for lines and 0-based for cols: https://github.com/facebook/metro/blob/f2d80cebe66d3c64742f67259f41da26e83a0d8d/packages/metro/src/Server/symbolicate.js#L58-L60


assert_eq!(
sm.lookup_token(0, 11947).unwrap().to_tuple(),
("module.js", 1, 4, None)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This basically points to the throw token here (which is at line 2:5)

throw new Error("lets throw!");

sm.lookup_token(0, 11947).unwrap().to_tuple(),
("module.js", 1, 4, None)
);
assert_eq!(sm.get_original_function_name(11947), Some("foo"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix, this was returning <global> instead of foo as it thought it was outside the function scope.

@pablomatiasgomez pablomatiasgomez marked this pull request as ready for review March 10, 2025 21:40
src/hermes.rs Outdated
// https://github.com/facebook/metro/blob/f2d80cebe66d3c64742f67259f41da26e83a0d8d/packages/metro/src/Server/symbolicate.js#L58-L60
let (_mapping_idx, mapping) =
greatest_lower_bound(&function_map.mappings, &token.get_src(), |o| {
greatest_lower_bound(&function_map.mappings, &(token.get_src_line() + 1, token.get_src_col()), |o| {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could either do this, or change the mapping function to do (o.line - 1, o.column), let me know what do you prefer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doing it this way is fine.

@loewenheim
Copy link
Contributor

Hi, thank you very much for the contribution!

@pablomatiasgomez
Copy link
Contributor Author

@loewenheim thanks for the approval! I just fixed the lint error that was getting

@pablomatiasgomez
Copy link
Contributor Author

@loewenheim Can we run the workflow to see if the linter and tests pass?

@pablomatiasgomez
Copy link
Contributor Author

@loewenheim There were 2 cargo clippy issues (in https://github.com/getsentry/rust-sourcemap/actions/runs/13788693074/job/38764074330) that weren't part of my PR but were failing, I just fixed them, but let me know if you want those to be in a separate PR maybe?

@loewenheim
Copy link
Contributor

@pablomatiasgomez Apologies, I didn't realize those lint errors weren't part of your PR. Thank you for taking care of them!

@pablomatiasgomez
Copy link
Contributor Author

@loewenheim no worries! I just fixed another one 😅

@pablomatiasgomez
Copy link
Contributor Author

@loewenheim What is the process to get this merged? No rush on my end, just want to know if there's anything left on my end to do 😄

@loewenheim loewenheim merged commit 8342f22 into getsentry:master Mar 14, 2025
6 checks passed
@loewenheim
Copy link
Contributor

Just merged it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants