@Test public void testProduceDataSetUsingNotYamlStream() throws DataSetException { // GIVEN final IDataSetConsumer consumer = mock(IDataSetConsumer.class); final IDataSetProducer producer = new YamlDataSetProducer(jsonStream); producer.setConsumer(consumer); // WHEN try { producer.produce(); fail("DataSetException expected"); } catch (final DataSetException e) { // THEN assertThat(e.getCause(), instanceOf(ScannerException.class)); } }
/** * Loads messages * * @throws FatalNovaGuildsException when something goes wrong */ public void load() throws FatalNovaGuildsException { setupDirectories(); try { detectLanguage(); messages = Lang.loadConfiguration(messagesFile); //Fork, edit and compile NovaGuilds on your own if you want not to use the original prefix restorePrefix(); prefix = Message.CHAT_PREFIX.get(); prefixColor = ChatColor.getByChar(ChatColor.getLastColors(prefix).charAt(1)); LoggerUtils.info("Messages loaded: " + Config.LANG_NAME.getString()); } catch(ScannerException | IOException e) { throw new FatalNovaGuildsException("Failed to load messages", e); } }
public String getErrorMessage(Throwable e) { String errorMessage = e.getMessage(); if (e instanceof ScannerException && (errorMessage.startsWith(MAPPING_VALUES_NOT_ALLOWED_HERE_ERROR) || errorMessage.startsWith(SCANNING_A_SIMPLE_KEY_ERROR))) { errorMessage += KEY_VALUE_PAIR_MISSING_OR_INDENTATION_PROBLEM_MSG; } else if (e instanceof ConstructorException && errorMessage.startsWith(CANNOT_CREATE_PROPERTY_ERROR)) { if (errorMessage.contains(UNABLE_TO_FIND_PROPERTY_ERROR)) { //parse for undefined property name String truncatedErrorMessage = errorMessage.substring(errorMessage.indexOf(TRUNCATION_BEGINNING), errorMessage.indexOf(TRUNCATION_END)); String undefinedProperty = truncatedErrorMessage.substring(truncatedErrorMessage.indexOf("\'") + 1, truncatedErrorMessage.lastIndexOf("\'")); errorMessage += "Property \'" + undefinedProperty + "\' is not supported by CloudSlang. Check that \'" + undefinedProperty + "\' is indented properly."; } else if (errorMessage.contains(MAP_CONSTRUCTOR_NOT_FOUND_ERROR)) { errorMessage += KEY_VALUE_PAIR_MISSING_OR_INDENTATION_PROBLEM_MSG; } } return errorMessage; }
@Test public void testBadResource() throws Exception { this.processor.setResources(new ByteArrayResource( "foo: bar\ncd\nspam:\n foo: baz".getBytes())); this.exception.expect(ScannerException.class); this.exception.expectMessage("line 3, column 1"); this.processor.process(new MatchCallback() { @Override public void process(Properties properties, Map<String, Object> map) { } }); }
@Test public void testBadResource() throws Exception { YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); factory.setResources(new ByteArrayResource( "foo: bar\ncd\nspam:\n foo: baz".getBytes())); this.exception.expect(ScannerException.class); this.exception.expectMessage("line 3, column 1"); factory.getObject(); }
@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); } }
/** * Get {@link Properties} for a given {@code inputStream} treating it as a YAML file. * * @param inputStream input stream representing YAML file * @return properties representing values from {@code inputStream} * @throws IllegalStateException when unable to read properties */ @Override public Properties getProperties(InputStream inputStream) { requireNonNull(inputStream); Yaml yaml = new Yaml(); Properties properties = new Properties(); try (Reader reader = new UnicodeReader(inputStream)) { Object object = yaml.load(reader); if (object != null) { Map<String, Object> yamlAsMap = convertToMap(object); properties.putAll(flatten(yamlAsMap)); } return properties; } catch (IOException | ScannerException e) { throw new IllegalStateException("Unable to load yaml configuration from provided stream", e); } }
/** * Returns the value of a key-value pair for a given {@code key}, on the file located at {@code * appYamlPathString}. * * @return a String with the value, or an empty Optional if app.yaml isn't a regular file, or if * there is any error getting the value * @throws MalformedYamlFileException when an app.yaml isn't syntactically well formed */ private Optional<String> getValueFromAppYaml( @NotNull String appYamlPathString, @NotNull String key) throws MalformedYamlFileException { Yaml yamlParser = new Yaml(); Path appYamlPath = Paths.get(appYamlPathString); if (!Files.isRegularFile(appYamlPath)) { return Optional.empty(); } try (BufferedReader reader = Files.newBufferedReader(appYamlPath, Charset.defaultCharset())) { Object parseResult = yamlParser.load(reader); if (!(parseResult instanceof Map)) { return Optional.empty(); } // It's possible to get rid of this unchecked cast using a loadAs(file, // AppEngineYamlWebApp.class) sort of approach. Map<String, String> yamlMap = (Map<String, String>) parseResult; return yamlMap.containsKey(key) ? Optional.of(yamlMap.get(key)) : Optional.empty(); } catch (ScannerException se) { throw new MalformedYamlFileException(se); } catch (InvalidPathException | IOException ioe) { return Optional.empty(); } }
public static YamlCluster yamlToYamlObject(String ymlString) throws KaramelException { try { Yaml yaml = new Yaml(new Constructor(YamlCluster.class)); Object document = yaml.load(ymlString); return ((YamlCluster) document); } catch (ScannerException ex) { throw new KaramelException("Syntax error in the yaml!!", ex); } }
public ParseConfigException(ScannerException e) { Problem problem = new ConfigProblemBuilder(Problem.Severity.FATAL, "Could not parse your halconfig: " + e.getMessage()).build(); getProblems().add(problem); }
public YAMLException(ScannerException e, VirtualFile yaml) { super(e.getMessage() + " (in file " + yaml.relativePath() + " line " + (e.getProblemMark().getLine() + 1) + ", column " + (e.getProblemMark().getColumn() + 1) + ")", e); this.e = e; this.yaml = yaml; }