Skip to content
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

fix(create-neon): Render diagnostics to stderr in cargo build #1071

Merged
merged 1 commit into from
Sep 23, 2024

Conversation

kjvalencik
Copy link
Member

Currently, create-neon uses --message-format=json which outputs diagnostics (e.g., compile errors) to stdout in JSON metadata. This makes it difficult to see compiler errors. For example, I have started with the out-of-the-box Neon app and changed the return type of hello to be JsNumber.

$ npm run build

> [email protected] build
> npm run cargo-build -- --release


> [email protected] cargo-build
> cargo build --message-format=json > cargo.log --release

   Compiling example v0.1.0 (/private/tmp/example)
error: could not compile `example` (lib) due to 2 previous errors

The error message does not show. If I change to --message-format=json-render-diagnostics, artifacts will still be sent to stdout, but compile errors will be rendered in human readable form on stderr.

$ npm run build

> [email protected] build
> npm run cargo-build -- --release


> [email protected] cargo-build
> cargo build --message-format=json-render-diagnostics > cargo.log --release

   Compiling example v0.1.0 (/private/tmp/example)
error[E0308]: mismatched types
   --> src/lib.rs:4:8
    |
4   |     Ok(cx.string("hello node"))
    |     -- ^^^^^^^^^^^^^^^^^^^^^^^ expected `Handle<'_, JsNumber>`, found `Handle<'_, JsString>`
    |     |
    |     arguments to this enum variant are incorrect
    |
    = note: expected struct `Handle<'_, neon::prelude::JsNumber>`
               found struct `Handle<'_, JsString>`

@kjvalencik kjvalencik requested a review from dherman September 23, 2024 15:29
@kjvalencik kjvalencik force-pushed the kv/render-diagnostics branch from 823c92c to 9d59b71 Compare September 23, 2024 15:35
Copy link
Collaborator

@dherman dherman left a comment

Choose a reason for hiding this comment

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

Thank you for explaining this -- I hadn't quite understood the difference between --json and --json-render-diagnostics. This is definitely better.

@kjvalencik kjvalencik merged commit e281554 into main Sep 23, 2024
9 checks passed
@kjvalencik kjvalencik deleted the kv/render-diagnostics branch September 23, 2024 16:09
@dherman
Copy link
Collaborator

dherman commented Sep 23, 2024

Published to the registry at [email protected]! 🚀

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