Skip to content

refactor: print diagnostic code in front of message#10227

Closed
LingyuCoder wants to merge 1 commit intomainfrom
refactor/print-diagnostic-code
Closed

refactor: print diagnostic code in front of message#10227
LingyuCoder wants to merge 1 commit intomainfrom
refactor/print-diagnostic-code

Conversation

@LingyuCoder
Copy link
Contributor

Summary

close #9724
perhaps relate to #10081

Print diagnostic code in front of message. This enables us to quickly identify the scope where the error lies.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@LingyuCoder LingyuCoder requested review from Copilot and h-a-n-a April 28, 2025 09:04
@netlify
Copy link

netlify bot commented Apr 28, 2025

Deploy Preview for rspack ready!

Name Link
🔨 Latest commit 7c83c98
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/680f4499ff8463000810147f
😎 Deploy Preview https://deploy-preview-10227--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors diagnostic messages by printing a diagnostic code in front of the message for improved clarity when identifying error scopes. Key changes include updates to the formatting logic in error handling (e.g. in concatErrorMsgAndStack and loader-runner), standardized diagnostic code labels across multiple plugins, and consistent renaming of diagnostic titles in tests and plugins.

Reviewed Changes

Copilot reviewed 14 out of 18 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/rspack/src/util/index.ts Updates error message formatting by stripping the error name from the stack trace.
packages/rspack/src/loader-runner/index.ts Simplifies diagnostic message generation by using the original diagnostic message.
packages/rspack-test-tools/tests/errorCases/warning-map.js Renames the diagnostic name to align with updated formatting.
crates/rspack_plugin_wasm/src/parser_and_generator.rs Refactors error diagnostic titles to the shorter "WasmParser".
crates/rspack_plugin_warn_sensitive_module/src/lib.rs Renames the diagnostic title from "Sensitive Modules Warn" to "WarnCaseSensitive".
crates/rspack_plugin_sri/src/lib.rs Adjusts the SRI error message for better clarity.
crates/rspack_plugin_size_limits/src/lib.rs Changes warning titles from descriptive messages to the concise "SizeLimits".
crates/rspack_plugin_mf/src/sharing/provide_shared_plugin.rs Updates plugin title from a verbose string to "ProvideShared".
crates/rspack_plugin_mf/src/sharing/consume_shared_plugin.rs Updates plugin title but introduces a potential typo in the new title.
crates/rspack_plugin_css/src/plugin/impl_plugin_for_css_plugin.rs Shortens diagnostic title to "CssPlugin".
crates/rspack_plugin_copy/src/lib.rs Standardizes error messages by using "CopyPlugin" consistently.
crates/rspack_plugin_circular_dependencies/src/lib.rs Streamlines the circular dependency error message format.
crates/rspack_error/src/graphical.rs Adjusts the error rendering to include the diagnostic code in the output.
crates/rspack_core/src/diagnostics.rs Modifies display implementations for module build and parse errors for consistency.
Files not reviewed (4)
  • packages/rspack-test-tools/tests/snapshots/NewCodeSplitting-stats-output.test.js.snap: Language not supported
  • packages/rspack-test-tools/tests/snapshots/StatsOutput.test.js.snap: Language not supported
  • packages/rspack-test-tools/tests/diagnosticsCases/module-build-failed/loader-emit-diagnostic/stats.err: Language not supported
  • packages/rspack-test-tools/tests/diagnosticsCases/plugins/circular-dependency-plugin/stats.err: Language not supported
Comments suppressed due to low confidence (1)

crates/rspack_plugin_mf/src/sharing/consume_shared_plugin.rs:475

  • The diagnostic title 'CosumeShared' appears to be a typo. It should likely be 'ConsumeShared' for consistency and clarity.
    +    "CosumeShared"

@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Apr 28, 2025
impl miette::Diagnostic for ModuleBuildError {
fn code<'a>(&'a self) -> Option<Box<dyn std::fmt::Display + 'a>> {
Some(Box::new("ModuleBuildError"))
Some(Box::new("Module build failed"))
Copy link
Contributor

@h-a-n-a h-a-n-a Apr 28, 2025

Choose a reason for hiding this comment

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

Diagnostic code should be PascalCase. This is intended to work as WebpackError.name in webpack.

.expect("failed to obtain lock of `diagnostics`")
.push(Diagnostic::error(
"CopyRspackPlugin Error".into(),
"CopyPlugin".into(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Both Diagnostic::warn and Diagnostic::error are legacy APIs. So the title is not the same as which in the TraceableError. I prefer to align this part with TraceableError.

@h-a-n-a
Copy link
Contributor

h-a-n-a commented Apr 28, 2025

IMO, If we need to print the StatsError.code to user, which is not currently available in rspack, we might need to add something new to DefaultStatsXxxxPlugin API instead of changing the current error code and stuff. This has partly been done in this PR. #10057

@codspeed-hq
Copy link

codspeed-hq bot commented Apr 28, 2025

CodSpeed Performance Report

Merging #10227 will not alter performance

Comparing refactor/print-diagnostic-code (7c83c98) with main (d0b7693)

Summary

✅ 11 untouched benchmarks

@LingyuCoder
Copy link
Contributor Author

IMO, If we need to print the StatsError.code to user, which is not currently available in rspack, we might need to add something new to DefaultStatsXxxxPlugin API instead of changing the current error code and stuff. This has partly been done in this PR. #10057

Ok, I will close this PR and perhaps do some work after #10057 is merged.

@h-a-n-a
Copy link
Contributor

h-a-n-a commented Apr 28, 2025

IMO, If we need to print the StatsError.code to user, which is not currently available in rspack, we might need to add something new to DefaultStatsXxxxPlugin API instead of changing the current error code and stuff. This has partly been done in this PR. #10057

Ok, I will close this PR and perhaps do some work after #10057 is merged.

LGTM

@chenjiahan chenjiahan deleted the refactor/print-diagnostic-code branch December 18, 2025 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Display diagnostic title in error logs

2 participants