Skip to content

Commit

Permalink
surfacing the file parsing error message so that its easier for the u…
Browse files Browse the repository at this point in the history
…sers to detect the issue
  • Loading branch information
sanjusoftware committed Dec 12, 2016
1 parent e18f99d commit b2734cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/cd/go/plugin/config/yaml/YamlFileParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public JsonConfigCollection parseFiles(File baseDir, String[] files) {
} catch (FileNotFoundException ex) {
collection.addError("File matching Go YAML pattern disappeared", file);
} catch (IOException ex) {
collection.addError("IO error when reading Go YAML file", file);
collection.addError(ex.getMessage() +" : "+ ex.getCause().getMessage() + " : ", file);
} finally {
if (inputStream != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,27 @@ public void shouldRespondSuccessWithErrorMessagesToParseDirectoryRequestWhenDupl
assertThat(errors.get(0).getAsJsonObject().getAsJsonPrimitive("location").getAsString(), is("duplicate-materials.gocd.yaml"));
}

@Test
public void shouldRespondSuccessWithErrorMessagesToParseDirectoryRequestWhenParsingErrorCaseFile() throws UnhandledRequestTypeException, IOException {
setupCase("simpleInvalidCase", "invalid-materials");

DefaultGoPluginApiRequest parseDirectoryRequest = new DefaultGoPluginApiRequest("configrepo", "1.0", "parse-directory");
String requestBody = "{\n" +
" \"directory\":\"simpleInvalidCase\",\n" +
" \"configurations\":[]\n" +
"}";
parseDirectoryRequest.setRequestBody(requestBody);

GoPluginApiResponse response = plugin.handle(parseDirectoryRequest);
assertThat(response.responseCode(), is(DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE));
JsonObject responseJsonObject = getJsonObjectFromResponse(response);
JsonArray errors = (JsonArray) responseJsonObject.get("errors");
JsonArray pipelines = responseJsonObject.get("pipelines").getAsJsonArray();
assertThat(pipelines.size(), is(0));
assertThat(errors.get(0).getAsJsonObject().getAsJsonPrimitive("message").getAsString(), is("Error parsing YAML. : Line 21, column 0: Expected a 'block end' but found: scalar : "));
assertThat(errors.get(0).getAsJsonObject().getAsJsonPrimitive("location").getAsString(), is("invalid-materials.gocd.yaml"));
}

private void setupCase(String folder, String caseName) throws IOException {
File caseFolder = new File(folder);
FileUtils.deleteDirectory(caseFolder);
Expand Down

0 comments on commit b2734cb

Please sign in to comment.