typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

fix: improve panic message for unspecified ScriptKind in `Parser::initializeState`

Open camc314 opened this issue 4 months ago • 4 comments

Currently this message give no diagnostic information, and no information about how to fix the issue.

ScriptKindUnknown, probably comes from here when the extension failed to be fetched, by including the filename in the diagnostic, it should allow devs/users to more easily track down the source of the panic

https://github.com/microsoft/typescript-go/blob/fc4f2039c877fd3e851a3653f7a518346a023b32/internal/core/core.go#L434-L451

Ref: https://github.com/oxc-project/oxc/issues/12950

camc314 avatar Aug 11 '25 14:08 camc314

I think we avoid including user-specified data in panics/throws just because that means we can't collect it for telemetry on errors. But maybe the old code already broke this rule?

jakebailey avatar Aug 11 '25 16:08 jakebailey

Hmm that's a fair point, feel free to close. However i do feel that the value in extra debugging info is valuable.

A large number of the panics do have additional data:

Total panics: (ignoring _test.go files)

$ rg -t go --count-matches --no-filename '\bpanic\s*\('  -g '!**/*_test.go' | awk '{s+=$1} END{print s}'
538

Panics with either string concatenation, or string formatting:

$ rg -t go --count-matches --no-filename -g '!**/*_test.go'   -e 'panic\(\s*fmt\.\w+\s*\('   -e 'panic\(\s*(?:"(?:[^"\\]|\\.)*"|`[^`]*`)\s*\+' | awk '{s+=$1} END{print s}'
161

For telemetry, couldn't just the first part of the string be matched?

camc314 avatar Aug 11 '25 16:08 camc314

Searching for just prints in panics isn't really enough, given many of those aren't printing out filenames or file contents.

We'll have to think about this, but definitely be aware that we don't even have an API at the moment, so oxc's usage really comes without warranty (they're probably "holding it wrong", since we haven't exactly optimized for anyone using it outside our own). 😅

jakebailey avatar Aug 11 '25 16:08 jakebailey

Honestly, I think we can just take this; NewSourceFile already panics with a filename. I would just merge from main, however.

jakebailey avatar Dec 09 '25 06:12 jakebailey