Java Code Examples for com.google.devtools.build.lib.syntax.EvalException#getMessage()

The following examples show how to use com.google.devtools.build.lib.syntax.EvalException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfiguredAttributeMapper.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T get(String attributeName, Type<T> type) {
  try {
    return getAndValidate(attributeName, type);
  } catch (EvalException e) {
    // Callers that reach this branch should explicitly validate the attribute through an
    // appropriate call and handle the exception directly. This method assumes
    // pre-validated attributes.
    throw new IllegalStateException(
        "lookup failed on attribute " + attributeName + ": " + e.getMessage());
  }
}
 
Example 2
Source File: DefaultPackageArguments.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
protected void process(Package.Builder pkgBuilder, Location location,
    List<Label> value) throws EvalException {
  try {
    pkgBuilder.setDefaultVisibility(
        PackageUtils.getVisibility(pkgBuilder.getBuildFileLabel(), value));
  } catch (EvalException e) {
    throw new EvalException(location, e.getMessage());
  }
}
 
Example 3
Source File: StarlarkRuleConfiguredTargetUtil.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the message of the given exception after removing the stack trace, if present.
 */
private static String getMessageWithoutStackTrace(EvalException ex) {
  if (ex instanceof EvalExceptionWithStackTrace) {
    return ((EvalExceptionWithStackTrace) ex).getOriginalMessage();
  }
  return ex.getMessage();
}
 
Example 4
Source File: CcToolchainFeaturesTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
private String getFlagParsingError(String value) throws Exception {
  try {
    getExpansionOfFlag(value);
    fail("Expected EvalException");
    return "";
  } catch (EvalException e) {
    return e.getMessage();
  }
}
 
Example 5
Source File: StarlarkAttrModule.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public Descriptor labelAttribute(
    Object defaultValue, // Label | String | LateBoundDefaultApi | StarlarkFunction
    String doc,
    Boolean executable,
    Object allowFiles,
    Object allowSingleFile,
    Boolean mandatory,
    Sequence<?> providers,
    Object allowRules,
    Object cfg,
    Sequence<?> aspects,
    StarlarkThread thread)
    throws EvalException {
  BazelStarlarkContext.from(thread).checkLoadingOrWorkspacePhase("attr.label");
  try {
    ImmutableAttributeFactory attribute =
        createAttributeFactory(
            BuildType.LABEL,
            doc,
            optionMap(
                DEFAULT_ARG,
                defaultValue,
                EXECUTABLE_ARG,
                executable,
                ALLOW_FILES_ARG,
                allowFiles,
                ALLOW_SINGLE_FILE_ARG,
                allowSingleFile,
                MANDATORY_ARG,
                mandatory,
                PROVIDERS_ARG,
                providers,
                ALLOW_RULES_ARG,
                allowRules,
                CONFIGURATION_ARG,
                cfg,
                ASPECTS_ARG,
                aspects),
            thread,
            "label");
    return new Descriptor("label", attribute);
  } catch (EvalException e) {
    throw new EvalException(null, e.getMessage(), e);
  }
}
 
Example 6
Source File: StarlarkAttrModule.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public Descriptor labelListAttribute(
    Boolean allowEmpty,
    Object defaultValue, // Sequence | StarlarkFunction
    String doc,
    Object allowFiles,
    Object allowRules,
    Sequence<?> providers,
    Sequence<?> flags,
    Boolean mandatory,
    Object cfg,
    Sequence<?> aspects,
    StarlarkThread thread)
    throws EvalException {
  BazelStarlarkContext.from(thread).checkLoadingOrWorkspacePhase("attr.label_list");
  Map<String, Object> kwargs =
      optionMap(
          DEFAULT_ARG,
          defaultValue,
          ALLOW_FILES_ARG,
          allowFiles,
          ALLOW_RULES_ARG,
          allowRules,
          PROVIDERS_ARG,
          providers,
          FLAGS_ARG,
          flags,
          MANDATORY_ARG,
          mandatory,
          ALLOW_EMPTY_ARG,
          allowEmpty,
          CONFIGURATION_ARG,
          cfg,
          ASPECTS_ARG,
          aspects);
  try {
    ImmutableAttributeFactory attribute =
        createAttributeFactory(BuildType.LABEL_LIST, doc, kwargs, thread, "label_list");
    return new Descriptor("label_list", attribute);
  } catch (EvalException e) {
    throw new EvalException(null, e.getMessage(), e);
  }
}
 
Example 7
Source File: StarlarkAttrModule.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public Descriptor labelKeyedStringDictAttribute(
    Boolean allowEmpty,
    Object defaultValue, // Dict | StarlarkFunction
    String doc,
    Object allowFiles,
    Object allowRules,
    Sequence<?> providers,
    Sequence<?> flags,
    Boolean mandatory,
    Object cfg,
    Sequence<?> aspects,
    StarlarkThread thread)
    throws EvalException {
  BazelStarlarkContext.from(thread).checkLoadingOrWorkspacePhase("attr.label_keyed_string_dict");
  Map<String, Object> kwargs =
      optionMap(
          DEFAULT_ARG,
          defaultValue,
          ALLOW_FILES_ARG,
          allowFiles,
          ALLOW_RULES_ARG,
          allowRules,
          PROVIDERS_ARG,
          providers,
          FLAGS_ARG,
          flags,
          MANDATORY_ARG,
          mandatory,
          ALLOW_EMPTY_ARG,
          allowEmpty,
          CONFIGURATION_ARG,
          cfg,
          ASPECTS_ARG,
          aspects);
  try {
    ImmutableAttributeFactory attribute =
        createAttributeFactory(
            BuildType.LABEL_KEYED_STRING_DICT,
            doc,
            kwargs,
            thread,
            "label_keyed_string_dict");
    return new Descriptor("label_keyed_string_dict", attribute);
  } catch (EvalException e) {
    throw new EvalException(null, e.getMessage(), e);
  }
}