public MetadataList readConfig(String mappingFile) { try { File file = new File(mappingFile); log.info("Loading mapping file from " + file.getAbsolutePath()); InputStream configStream = new FileInputStream(file); return readConfig(configStream); } catch (FileNotFoundException e) { log.warn("No configuration found"); } catch (ParserException pe) { log.error(pe); } return null; }
@Override protected Map<Object, Object> constructMapping(MappingNode node) { try { return super.constructMapping(node); } catch (IllegalStateException ex) { throw new ParserException("while parsing MappingNode", node.getStartMark(), ex.getMessage(), node.getEndMark()); } }
@Test public void testBadDocumentStart() throws Exception { this.processor.setResources(new ByteArrayResource( "foo # a document\nbar: baz".getBytes())); this.exception.expect(ParserException.class); this.exception.expectMessage("line 2, column 1"); this.processor.process(new MatchCallback() { @Override public void process(Properties properties, Map<String, Object> map) { } }); }
@Test public void testLoadResourcesWithInternalOverride() throws Exception { YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); factory.setResources(new ByteArrayResource( "foo: bar\nspam:\n foo: baz\nfoo: bucket".getBytes())); exception.expect(ParserException.class); factory.getObject(); }
private Iterable<Object> readYaml(Option<FileArtifact> manifestFile) { try { Yaml yaml = new Yaml(); return (Iterable<Object>) yaml.loadAll(manifestFile.get().content()); } catch (ParserException e) { throw new ManifestParsingException("manifest.yml file in .atomist is malformed:\n\n%s", e.getMessage()); } }
@VisibleForTesting static String findRuntime(StageFlexibleConfiguration config) throws IOException { try { // verification for app.yaml that contains runtime:java Path appYaml = config.getAppEngineDirectory().toPath().resolve(APP_YAML); return new AppYaml(appYaml).getRuntime(); } catch (ScannerException | ParserException ex) { throw new AppEngineException("Malformed 'app.yaml'.", ex); } }
/** * {@inheritDoc} */ @Override public ConfigurationResult deserialize(InputStream input) throws ConfigurationException { String content = new Scanner(input).useDelimiter("\\A").next(); HierarchicalConfiguration configuration = new HierarchicalConfiguration(); List<IncludeReference> includes = new ArrayList<>(); if (!content.isEmpty()) { Object tree; try { tree = yaml.load(content); } catch (ParserException e) { throw new ConfigurationException("Failed to parse input as valid YAML.", e); } traverseTreeAndLoad(configuration.getRootNode(), null, includes, tree); // Get the references from the special 'extends' key. for (String reference : configuration.getStringArray("extends")) { includes.add(new IncludeReference(reference)); } } return new ConfigurationResult(configuration, includes); }
public String rewriteMessage(YAMLException exception) { if (exception instanceof ParserException) { if ("while parsing a block mapping".equals(((ParserException) exception).getContext())) { return Messages.error_yaml_parser_indentation; } } return exception != null ? exception.getLocalizedMessage() : null; }
@Test(expected = ParserException.class) public void testDuplicateKey() throws Exception { this.factory.setResources(new ByteArrayResource[] {new ByteArrayResource( "mymap:\n foo: bar\nmymap:\n bar: foo".getBytes())}); this.factory.getObject().get("mymap"); }
public ParseConfigException(ParserException e) { Problem problem = new ConfigProblemBuilder(Problem.Severity.FATAL, "Could not parse your halconfig: " + e.getMessage()).build(); getProblems().add(problem); }