Skip to content

Conversation

@will-wow
Copy link
Contributor

When trying to publish a custom plugin to the BSR, I had some trouble figuring out why it was failing to generate an SDK.

I ended up debugging the problem by implementing a custom transpiler that prints extra diagnostic information when results are skipped, since these errors show up in the npm install log when it fails to generate.

So, this seems like it could be useful for others trying to debug SDK generation failures in the future.

This generates an error like:

protoc-gen-es-required: A problem occurred during transpilation and files were not generated.

Generating Files:

buf/validate/validate_required.ts
factory_execution/cycle_time/v1/cycle_time_required.ts

Diagnostics:

Property 'in' of exported interface has or is using private name 'Uint8Array'.
Property 'notIn' of exported interface has or is using private name 'Uint8Array'.
Property 'example' of exported interface has or is using private name 'Uint8Array'.

@CLAassistant
Copy link

CLAassistant commented Oct 30, 2024

CLA assistant check
All committers have signed the CLA.

@timostamm timostamm changed the title print diagnostics when a protoplugin fails to emit files. Print diagnostics when a protoplugin fails to emit files Oct 31, 2024
Copy link
Member

@timostamm timostamm left a comment

Choose a reason for hiding this comment

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

In general, I recommend the following approach if transpilation fails:

  • Generate the same input with the plugin option target=ts to local files
  • Compile the local files with TypeScript v5.4.5 (the version that transpilation uses)
  • Inspect errors in an IDE

This will give you all error details, and let's you iterate quickly. Of course it's still helpful to print diagnostics, so thanks for the PR!

I've pushed up 7e17860 to use the TypeScript compiler to format diagnostics (it handles locations and error chains):

A problem occurred during transpilation and files were not generated.  Contact the plugin author for support.

test.ts(3,17): error TS4033: Property 'p' of exported interface has or is using private name 'P'.
test.ts(8,17): error TS4033: Property 'p' of exported interface has or is using private name 'P'.
test.ts(13,17): error TS4033: Property 'p' of exported interface has or is using private name 'P'.
2 more diagnostics elided

It also prints at most three diagnostics because the error message can potentially grow to megabytes of text.

@timostamm timostamm merged commit d04b861 into bufbuild:main Oct 31, 2024
@timostamm timostamm mentioned this pull request Nov 1, 2024
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.

3 participants