blob: 4795d7c5b1439ade5963eed1e0a4084d4322eca8 [file] [log] [blame]
jcater2050fad2020-04-15 10:29:28 -07001// Copyright 2020 The Bazel Authors. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package com.google.devtools.build.lib.skyframe;
15
Googler6214f8f2023-06-20 06:36:45 -070016import static com.google.devtools.build.lib.analysis.config.BuildConfigurationValue.configurationIdMessage;
17
jhorvitz33f76482021-10-28 10:13:26 -070018import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
jcater2050fad2020-04-15 10:29:28 -070019import com.google.devtools.build.lib.causes.AnalysisFailedCause;
20import com.google.devtools.build.lib.causes.Cause;
mschaller859c9ac2020-09-25 16:09:19 -070021import com.google.devtools.build.lib.causes.LabelCause;
jcater2050fad2020-04-15 10:29:28 -070022import com.google.devtools.build.lib.cmdline.Label;
23import com.google.devtools.build.lib.collect.nestedset.NestedSet;
24import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
mschaller859c9ac2020-09-25 16:09:19 -070025import com.google.devtools.build.lib.server.FailureDetails.Analysis;
26import com.google.devtools.build.lib.server.FailureDetails.Analysis.Code;
27import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
28import com.google.devtools.build.lib.util.DetailedExitCode;
jcater2050fad2020-04-15 10:29:28 -070029import javax.annotation.Nullable;
30
31/** An exception indicating that there was a problem creating an aspect. */
Googlerc031fab2024-03-18 07:34:32 -070032public final class AspectCreationException extends AbstractSaneAnalysisException {
jcater2050fad2020-04-15 10:29:28 -070033 private final NestedSet<Cause> causes;
mschaller859c9ac2020-09-25 16:09:19 -070034 // TODO(b/138456686): if warranted by a need for finer-grained details, replace the constructors
35 // that specify the general Code.ASPECT_CREATION_FAILED
36 private final DetailedExitCode detailedExitCode;
jcater2050fad2020-04-15 10:29:28 -070037
mschaller859c9ac2020-09-25 16:09:19 -070038 public AspectCreationException(
39 String message, NestedSet<Cause> causes, DetailedExitCode detailedExitCode) {
jcater2050fad2020-04-15 10:29:28 -070040 super(message);
41 this.causes = causes;
mschaller859c9ac2020-09-25 16:09:19 -070042 this.detailedExitCode = detailedExitCode;
43 }
44
45 public AspectCreationException(
46 String message,
47 Label currentTarget,
jhorvitz33f76482021-10-28 10:13:26 -070048 @Nullable BuildConfigurationValue configuration,
mschaller859c9ac2020-09-25 16:09:19 -070049 DetailedExitCode detailedExitCode) {
50 this(
51 message,
52 NestedSetBuilder.<Cause>stableOrder()
Googler6214f8f2023-06-20 06:36:45 -070053 .add(
54 new AnalysisFailedCause(
55 currentTarget, configurationIdMessage(configuration), detailedExitCode))
mschaller859c9ac2020-09-25 16:09:19 -070056 .build(),
57 detailedExitCode);
jcater2050fad2020-04-15 10:29:28 -070058 }
59
60 public AspectCreationException(
jhorvitz33f76482021-10-28 10:13:26 -070061 String message, Label currentTarget, @Nullable BuildConfigurationValue configuration) {
jcater2050fad2020-04-15 10:29:28 -070062 this(
63 message,
mschaller859c9ac2020-09-25 16:09:19 -070064 currentTarget,
65 configuration,
66 createDetailedExitCode(message, Code.ASPECT_CREATION_FAILED));
67 }
68
69 public AspectCreationException(
70 String message, Label currentTarget, DetailedExitCode detailedExitCode) {
71 this(message, currentTarget, null, detailedExitCode);
jcater2050fad2020-04-15 10:29:28 -070072 }
73
74 public AspectCreationException(String message, Label currentTarget) {
mschaller859c9ac2020-09-25 16:09:19 -070075 this(
76 message, currentTarget, null, createDetailedExitCode(message, Code.ASPECT_CREATION_FAILED));
jcater2050fad2020-04-15 10:29:28 -070077 }
78
mschaller859c9ac2020-09-25 16:09:19 -070079 public AspectCreationException(String message, LabelCause cause) {
80 this(
81 message,
82 NestedSetBuilder.<Cause>stableOrder().add(cause).build(),
83 cause.getDetailedExitCode());
jcater2050fad2020-04-15 10:29:28 -070084 }
85
86 public NestedSet<Cause> getCauses() {
87 return causes;
88 }
mschaller859c9ac2020-09-25 16:09:19 -070089
90 @Override
91 public DetailedExitCode getDetailedExitCode() {
92 return detailedExitCode;
93 }
94
95 private static DetailedExitCode createDetailedExitCode(String message, Code code) {
96 return DetailedExitCode.of(
97 FailureDetail.newBuilder()
98 .setMessage(message)
99 .setAnalysis(Analysis.newBuilder().setCode(code))
100 .build());
101 }
jcater2050fad2020-04-15 10:29:28 -0700102}