-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SourceMap.lookup_line
panics when position is not found
#2757
Comments
This is the problematic part. |
That definitely makes sense as an implementation detail, but the API is still a bit misleading. The documentation for the function says:
which I guess is technically true, but in my mind not returning a line number does not mean that the library panics. Perhaps we should just update the documentation to cover the case when the function panics? |
Yeah, I think it's good change. |
Ran into this problem when mapping a Span to line/col in a plugin. One of the nodes had a position of pub fn lookup_source_file_in(
files: &[Lrc<SourceFile>],
pos: BytePos,
) -> Option<Lrc<SourceFile>> {
if pos.is_dummy() {
return None;
} Would it be better to have the interface return |
Related: #5535 (Not the same issue, but related with error handling) I agree hard panic is not something desirable as there's no way consumers to workaround / ignore failures. |
Describe the bug
I'm using SWC as a library in a dead code analysis tool. I noticed that
swc_common::source_map::SourceMap.lookup_line
panics when the given byte position cannot be found from the source map, for example when usingSourceMap::default()
as a placeholder. I assume this is unintentional, as the function returns aResult
, and there is some error handling code inlookup_line_with
. The issue seems to be inlookup_source_file
, which explicitly panics when the source file is not found.Input code
Config
No response
Playground link
No response
Expected behavior
I would expect
lookup_source_file
to do the necessary error handling so thatlookup_line
never throws under any regular circumstances.Version
swc_common = "0.14.6"
Additional context
No response
The text was updated successfully, but these errors were encountered: