private void addError(String message, Object... params) { diagCollector.addDiag( Diag.error(location, "In path template '" + template + "': " + message, params)); hadErrors = true; } }
public void error(Location location, String message, Object...params) { diag.addDiag(Diag.error(location, message, params)); }
private void addError(String message, Object... params) { diagCollector.addDiag( Diag.error(location, "In path template '" + template + "': " + message, params)); hadErrors = true; } }
public void error(Location location, String message, Object... params) { diag.addDiag(Diag.error(location, message, params)); }
public void error(Location location, String message, Object...params) { diag.addDiag(Diag.error(location, message, params)); }
@Override public Diag apply(String input) { return Diag.error(TEST_LOCATION, "In path template '" + path + "': " + input); }}).toList();
private ImmutableList<String> getResourceLines(String resourceFileName) { try { InputStream fileStream = ConfigProto.class.getResourceAsStream(resourceFileName); if (fileStream == null) { throw new FileNotFoundException(resourceFileName); } InputStreamReader fileReader = new InputStreamReader(fileStream, Charsets.UTF_8); return ImmutableList.copyOf(CharStreams.readLines(fileReader)); } catch (IOException e) { diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Exception: %s", e.getMessage())); throw new RuntimeException(e); } }
public static Document createDocumentAndLog(String discoveryDocPath, DiagCollector diagCollector) throws IOException { Document document = null; try { document = createDocument(discoveryDocPath); } catch (FileNotFoundException e) { diagCollector.addDiag( Diag.error(SimpleLocation.TOPLEVEL, "File not found: " + discoveryDocPath)); } catch (IOException e) { diagCollector.addDiag( Diag.error(SimpleLocation.TOPLEVEL, "Failed to read Discovery Doc: " + discoveryDocPath)); } return document; } }
private void checkMatchingMetrics(Service.Builder serviceBuilder, MetricRule metricRule) { Set<String> definedMetrics = new HashSet<>(); for (MetricDescriptor definedMetric : serviceBuilder.getMetricsList()) { definedMetrics.add(definedMetric.getName()); } Set<String> missingMetrics = Sets.difference(metricRule.getMetricCosts().keySet(), definedMetrics); if (!missingMetrics.isEmpty()) { diagCollector.addDiag( Diag.error( new SimpleLocation(MetricRuleGenerator.QUOTA_SWAGGER_EXTENSION), "Quota Extension for method '%s' references undefined metric(s) '%s'", metricRule.getSelector(), Joiner.on(',').join(missingMetrics))); } }
private void error(String message, Object... args) { model .getDiagReporter() .getDiagCollector() .addDiag(Diag.error(SimpleLocation.TOPLEVEL, message, args)); }
private Model setupModel() { // Prevent INFO messages from polluting the log. Logger.getLogger("").setLevel(Level.WARNING); try { serviceConfig = generateServiceConfig(); } catch (IOException e) { getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unexpected exception:%n%s", Throwables.getStackTraceAsString(e))); } model = Model.create(serviceConfig); onErrorsExit(); // Register standard processors. StandardSetup.registerStandardProcessors(model); // Register standard config aspects. StandardSetup.registerStandardConfigAspects(model); return model; }
private void addType(Location location, String fullName, TypeRef type) { String typeName = SymbolTable.getTypeNameInSymbolTable(fullName); TypeRef old = types.put(typeName , type); if (old != null) { model .getDiagReporter() .report( Diag.error( location, "Duplicate declaration of type '%s'. Previous location: %s", fullName, old.getLocation().getDisplayString())); } } }
private Model setupModel() { // Prevent INFO messages from polluting the log. Logger.getLogger("").setLevel(Level.WARNING); try { serviceConfig = generateServiceConfig(); } catch (IOException e) { getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unexpected exception:%n%s", Throwables.getStackTraceAsString(e))); } model = Model.create(serviceConfig); onErrorsExit(); // Register standard processors. StandardSetup.registerStandardProcessors(model); // Register standard config aspects. StandardSetup.registerStandardConfigAspects(model); return model; }
private void addType(Location location, String fullName, TypeRef type) { String typeName = SymbolTable.getTypeNameInSymbolTable(fullName); TypeRef old = types.put(typeName , type); if (old != null) { model .getDiagReporter() .report( Diag.error( location, "Duplicate declaration of type '%s'. Previous location: %s", fullName, old.getLocation().getDisplayString())); } } }
private void errorSince(int version, Element elem, String message, Object... params) { if (!errorContext.isEmpty()) { message = message + " " + errorContext + "."; } Diag diag = elem.getModel().getConfigVersion() >= version ? Diag.error(elem.getLocation(), message, params) : Diag.warning( elem.getLocation(), message + String.format( " Note: this will be an error for config version %s and later.", version), params); elem.getModel().getDiagReporter().report(diag); }
private void errorSince(int version, Element elem, String message, Object... params) { if (!errorContext.isEmpty()) { message = message + " " + errorContext + "."; } Diag diag = elem.getModel().getConfigVersion() >= version ? Diag.error(elem.getLocation(), message, params) : Diag.warning( elem.getLocation(), message + String.format( " Note: this will be an error for config version %s and later.", version), params); elem.getModel().getDiagReporter().report(diag); }
/** * Runs the tool. Returns a non-zero exit code on errors. */ public int run() { // Run tool specific code. if (!getDiagCollector().hasErrors()) { try { process(); } catch (Exception e) { getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unexpected exception:%n%s", Throwables.getStackTraceAsString(e))); } } reportDiag(); return getDiagCollector().hasErrors() ? 1 : 0; }
/** * Creates an instance of SingleResourceNameConfig based on a field. On errors, null will be * returned, and diagnostics are reported to the diag collector. */ static SingleResourceNameConfig createSingleResourceName( Resource resource, String pathTemplate, ProtoFile file, DiagCollector diagCollector) { PathTemplate nameTemplate; try { nameTemplate = PathTemplate.create(pathTemplate); } catch (ValidationException e) { diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, e.getMessage())); return null; } return new AutoValue_SingleResourceNameConfig( pathTemplate, nameTemplate, resource.getName(), resource.getName(), null, file); }
private FileDescriptorSet parseFileAsDescriptorSet( FileWrapper inputFile, ModelBuildOverrides registry, DiagCollector diagCollector) { ByteString extensionFile = inputFile.getFileContents(); try { return FileDescriptorSet.parseFrom(extensionFile, registry.getPlatformExtensions()); } catch (InvalidProtocolBufferException e) { diagCollector.addDiag( Diag.error( SimpleLocation.TOPLEVEL, "Cannot read file descriptor file '%s': %s", inputFile.getFilename(), e.getMessage())); return null; } }
private FileDescriptorSet parseFileAsDescriptorSet( FileWrapper inputFile, ModelBuildOverrides registry, DiagCollector diagCollector) { ByteString extensionFile = inputFile.getFileContents(); try { return FileDescriptorSet.parseFrom(extensionFile, registry.getPlatformExtensions()); } catch (InvalidProtocolBufferException e) { diagCollector.addDiag( Diag.error( SimpleLocation.TOPLEVEL, "Cannot read file descriptor file '%s': %s", inputFile.getFilename(), e.getMessage())); return null; } }