Skip to content

Commit

Permalink
Change a few promise artifact error messages to use PromiseArtifactId…
Browse files Browse the repository at this point in the history
… instead

Summary: Doing this so that we can reuse these error messages later in the stack during the promise artifact attr's resolution in the anon target context, in which we do not have access to the original `PromiseArtifact`, only the ID

Reviewed By: cjhopman

Differential Revision: D52741557

fbshipit-source-id: e5069e41532bc862f2dc6c7ab7d470a15d178e3a
  • Loading branch information
wendy728 authored and facebook-github-bot committed Jan 19, 2024
1 parent 65b6830 commit 4e5512d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
13 changes: 7 additions & 6 deletions app/buck2_anon_target/src/anon_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,16 +582,17 @@ pub(crate) fn init_eval_anon_target() {

pub(crate) fn init_get_promised_artifact() {
GET_PROMISED_ARTIFACT.init(|promise_artifact, ctx| {
Box::pin(async move { get_artifact_from_anon_target_analysis(promise_artifact, ctx).await })
Box::pin(
async move { get_artifact_from_anon_target_analysis(promise_artifact.id(), ctx).await },
)
});
}

async fn get_artifact_from_anon_target_analysis<'v>(
promise_artifact: &'v PromiseArtifact,
promise_id: &'v PromiseArtifactId,
ctx: &'v DiceComputations,
) -> anyhow::Result<Artifact> {
let promise_id = promise_artifact.id();
let owner = promise_artifact.owner();
let owner = promise_id.owner();
let analysis_result = match owner {
BaseDeferredKey::AnonTarget(anon_target) => {
AnonTargetKey::downcast(anon_target.dupe())?
Expand All @@ -600,7 +601,7 @@ async fn get_artifact_from_anon_target_analysis<'v>(
}
_ => {
return Err(PromiseArtifactResolveError::OwnerIsNotAnonTarget(
promise_artifact.clone(),
promise_id.clone(),
owner.clone(),
)
.into());
Expand All @@ -611,7 +612,7 @@ async fn get_artifact_from_anon_target_analysis<'v>(
.promise_artifact_map()
.get(promise_id)
.context(PromiseArtifactResolveError::NotFoundInAnalysis(
promise_artifact.clone(),
promise_id.clone(),
))
.cloned()
}
Expand Down
14 changes: 10 additions & 4 deletions app/buck2_build_api/src/artifact_groups/promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ pub enum PromiseArtifactResolveError {
"assert_short_path() was called with `short_path = {0}`, but it did not match the artifact's actual short path: `{1}`"
)]
ShortPathMismatch(ForwardRelativePathBuf, String),
#[error("Internal error: analysis result did not contain promise ({0})")]
NotFoundInAnalysis(PromiseArtifact),
#[error("Internal error: promise artifact ({0}) owner is ({1}), which is not an anon target")]
OwnerIsNotAnonTarget(PromiseArtifact, BaseDeferredKey),
#[error("Internal error: analysis result did not contain promise with ID ({0})")]
NotFoundInAnalysis(PromiseArtifactId),
#[error(
"Internal error: promise artifact (id: {0}) owner is ({1}), which is not an anon target"
)]
OwnerIsNotAnonTarget(PromiseArtifactId, BaseDeferredKey),
}

fn maybe_declared_at(location: &Option<FileSpan>) -> String {
Expand Down Expand Up @@ -74,6 +76,10 @@ impl PromiseArtifactId {
pub fn new(owner: BaseDeferredKey, id: usize) -> PromiseArtifactId {
Self { owner, id }
}

pub fn owner(&self) -> &BaseDeferredKey {
&self.owner
}
}

impl Display for PromiseArtifactId {
Expand Down

0 comments on commit 4e5512d

Please sign in to comment.