Unverified Commit 65e4a5ed authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

next-napi-bindings: keep issue-backed client update errors recoverable (#100924)

## Summary

When `node_modules/next` is briefly missing (e.g. during a concurrent
package install), `get_next_package` emits a `MissingNextFolderIssue`
and also returns an error. The server-changed subscription already
handles this: it uses `strongly_consistent_catch_collectables` and
reports the Issue. The client-changed subscription
(`endpoint_client_changed_subscribe`) propagated the error instead, so
`subscribe` turned it into a `TurbopackInternalError` and printed
`FATAL: An unexpected Turbopack error occurred: Next.js package not
found`.

With this change, the client-changed subscription reads
`endpoint_client_changed_with_issues_operation`, an operation that wraps
`endpoint_client_changed_operation` with the error handling. On success
it returns the client-changed `Completion` unchanged. On failure it
reads that operation's issues using the endpoint's issue filter: if an
Error-severity issue explains the failure, it returns a new
`Completion`, because the server subscription already surfaces the
Issue; other errors still propagate. Issues are read only on the failure
path, so the success path still doesn't depend on them. The subscription
itself only does a strongly consistent read of the wrapper, as before.

`test/development/app-dir/concurrent-install` covers this scenario.

## Verification

- `cargo clippy -p next-napi-bindings`

<!-- NEXT_JS_LLM -->


<!-- fleet 8482d6ce-bad2-4131-98e3-4a391357a1c9 -->

---------
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent be19b72b
...@@ -20,10 +20,10 @@ use turbo_rcstr::RcStr; ...@@ -20,10 +20,10 @@ use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
Completion, Effects, OperationVc, ReadRef, Vc, read_strongly_consistent_and_apply_effects, Completion, Effects, OperationVc, ReadRef, Vc, read_strongly_consistent_and_apply_effects,
}; };
use turbopack_core::issue::{IssueFilter, PlainIssue}; use turbopack_core::issue::{IssueFilter, IssueSeverity, PlainIssue};
use crate::next_api::utils::{ use crate::next_api::utils::{
DetachedVc, NapiIssue, SubscriptionTask, TurbopackResult, DetachedVc, NapiIssue, SubscriptionTask, TurbopackResult, get_issues,
strongly_consistent_catch_collectables, subscribe, strongly_consistent_catch_collectables, subscribe,
}; };
...@@ -271,6 +271,31 @@ async fn subscribe_issues_and_diags_operation( ...@@ -271,6 +271,31 @@ async fn subscribe_issues_and_diags_operation(
.cell()) .cell())
} }
/// [`endpoint_client_changed_operation`] with the error handling of the client-changed
/// subscription.
///
/// Transient build-graph errors (e.g. missing `node_modules/next` during a concurrent install) come
/// with an Issue. The server subscription (`subscribe_issues_and_diags_operation`) already reports
/// that Issue, so such an error is turned into a completion here instead of a
/// `TurbopackInternalError`. Issues are only read on this failure path, so the success path keeps
/// not depending on them: we don't want to be notified when they change.
#[turbo_tasks::function(operation, root)]
async fn endpoint_client_changed_with_issues_operation(
endpoint_op: OperationVc<OptionEndpoint>,
) -> Result<Vc<Completion>> {
let changed_op = endpoint_client_changed_operation(endpoint_op);
let Err(err) = changed_op.connect().await else {
return Ok(changed_op.connect());
};
let filter = issue_filter_from_endpoint(endpoint_op).await;
let issues = get_issues(changed_op, &filter).await?;
if issues.iter().any(|i| i.severity <= IssueSeverity::Error) {
Ok(Completion::new())
} else {
Err(err)
}
}
#[tracing::instrument(level = "info", name = "get client-side endpoint changes", skip_all)] #[tracing::instrument(level = "info", name = "get client-side endpoint changes", skip_all)]
#[napi(ts_return_type = "{ __napiType: \"RootTask\" }")] #[napi(ts_return_type = "{ __napiType: \"RootTask\" }")]
pub fn endpoint_client_changed_subscribe( pub fn endpoint_client_changed_subscribe(
...@@ -287,16 +312,11 @@ pub fn endpoint_client_changed_subscribe( ...@@ -287,16 +312,11 @@ pub fn endpoint_client_changed_subscribe(
&func, &func,
move || { move || {
async move { async move {
let changed_op = endpoint_client_changed_operation(endpoint_op); let changed_op = endpoint_client_changed_with_issues_operation(endpoint_op);
// We don't capture issues and diagnostics here since we don't want to be
// notified when they change. We also want errors to propagate so we don't use
// strongly_consistent_catch_collectibles either.
//
// This must be a *read*, not just a resolve, because we need the root task created // This must be a *read*, not just a resolve, because we need the root task created
// by `subscribe` to re-run when the `Completion`'s value changes (via equality), // by `subscribe` to re-run when the `Completion`'s value changes (via equality),
// even if the cell id doesn't change. // even if the cell id doesn't change.
// changed_op.read_strongly_consistent().await?;
let _ = changed_op.read_strongly_consistent().await?;
Ok(()) Ok(())
} }
.instrument(tracing::info_span!("client changes subscription")) .instrument(tracing::info_span!("client changes subscription"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment