Skip to content

Allow partially constructed stages#46

Merged
mxpv merged 3 commits intomainfrom
stage-builder
Apr 7, 2026
Merged

Allow partially constructed stages#46
mxpv merged 3 commits intomainfrom
stage-builder

Conversation

@mxpv
Copy link
Copy Markdown
Owner

@mxpv mxpv commented Apr 7, 2026

Ref: #45

This PR refactors how layers are collected when opening a stage.

Previously, any unresolvable transitive dependency (missing reference, payload, or sublayer) was a hard error that immediately aborted Stage::open. This matches strict correctness but doesn't match how C++ USD works — UsdStage::Open succeeds even when some referenced files are missing, reporting errors through GetCompositionErrors().

In this implementation, callers can provide an error callback via StageBuilder::on_error that is invoked for each composition error encountered. The callback receives a CompositionError with full context (asset path, referencing layer, dependency kind, prim path) and returns Result<()> — return Ok(()) to skip the dependency and continue, or Err to abort. The default behavior (no callback) preserves the current hard-error semantics.

mxpv added 3 commits April 7, 2026 11:09
Introduce error types for recoverable composition failures. CompositionError
is #[non_exhaustive] to allow future variants (e.g. arc cycles). DependencyKind
distinguishes sublayer, reference, and payload arcs.
Replace flat collect_asset_paths (Vec<String>) with collect_dependencies
returning typed Dependency structs with DependencyKind and prim_path.

Add collect_layers_with_handler for callers that need custom error
handling. The existing collect_layers passes a default handler that
converts errors to hard failures, preserving current behavior.
Stage::open now takes only a path and uses DefaultResolver with strict
error handling. For custom resolvers or error tolerance, use the builder:

  Stage::builder()
      .resolver(custom_resolver)
      .on_error(|e| { log(e); Ok(()) })
      .open(path)?

StageBuilder uses type parameters for both the resolver and error handler,
avoiding heap allocation in all paths.
@mxpv mxpv merged commit ce11f1e into main Apr 7, 2026
10 checks passed
@mxpv mxpv deleted the stage-builder branch April 7, 2026 19:38
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.

1 participant