public Mark getProblemMark() { return Mark.from(_source.getProblemMark()); } }
public Mark getProblemMark() { return Mark.from(_source.getProblemMark()); } }
@Test public void testWellKnownZoomContextWithOtherError() throws Exception { // Making sure that doing the grid validation doesn't screw up other validation later StringBuilder builder = new StringBuilder(); builder.append("grid:\n"); builder.append(" name: WebMercator\n"); builder.append("filter: foo\n"); List<MarkedYAMLException> errors = validate(builder.toString()); assertThat(errors.size(), is(1)); assertThat(errors.get(0).getProblemMark(), problemOn(3)); }
@Test public void testExpression() throws Exception { StringBuilder builder = new StringBuilder(); builder.append("rules:\n" + "- symbolizers:\n" + " - line:\n"); for (String key : EXPRESSION_KEYS) { builder.append(" ") .append(key) .append(": ") .append("${round([len] 1000)}") .append("\n"); // Invalid builder.append(" ") .append(key) .append(": ") .append("${round([len] / 1000)}") .append("\n"); // Valid } List<MarkedYAMLException> errors = validate(builder.toString()); assertThat(errors.size(), is(EXPRESSION_KEYS.length)); final int firstErrorLine = 4; for (int i = 0; i < EXPRESSION_KEYS.length; i++) { assertThat(errors.get(i).getProblemMark(), problemOn(i * 2 + firstErrorLine)); } }
@Test public void testNotWellKnownZoomContext() throws Exception { StringBuilder builder = new StringBuilder(); builder.append("grid:\n" + " name: SIGMA:957\n"); List<MarkedYAMLException> errors = validate(builder.toString()); assertThat(errors.size(), is(1)); assertThat(errors.get(0).getProblemMark(), problemOn(2)); }
@Test public void testColor() throws Exception { String ysld = "fill-color: 21xyz"; List<MarkedYAMLException> errors = validate(ysld); assertEquals(1, errors.size()); MarkedYAMLException e = errors.get(0); assertEquals(0, e.getProblemMark().getLine()); assertEquals(12, e.getProblemMark().getColumn()); }
@Test public void testFilter() throws Exception { String ysld = "filter: foo"; List<MarkedYAMLException> errors = validate(ysld); assertEquals(1, errors.size()); MarkedYAMLException e = errors.get(0); // Note this is the start of the expression, a better version would find the error within // the CQL assertThat(e.getProblemMark(), problemAt(1, 9)); }
@Test public void testMalformed() throws Exception { String ysld = "foo:\n" + " foo: bar\n" + " foo: bar\n"; List<MarkedYAMLException> errors = validate(ysld); assertEquals(1, errors.size()); MarkedYAMLException e = errors.get(0); assertEquals(2, e.getProblemMark().getLine()); }
@Test public void testZoomContextEPSG4326IsBad() throws Exception { StringBuilder builder = new StringBuilder(); builder.append("grid:\n" + " name: EPSG:4326\n"); ZoomContextFinder finder = createMock("finder", ZoomContextFinder.class); ZoomContext zctxt = createMock("zctxt", ZoomContext.class); expect(finder.get("EPSG:4326")).andStubReturn(zctxt); replay(finder, zctxt); List<MarkedYAMLException> errors = validate(builder.toString(), Collections.singletonList(finder)); assertThat(errors.size(), is(1)); assertThat(errors.get(0).getProblemMark(), problemOn(2)); verify(finder, zctxt); }
public Mark getProblemMark() { return Mark.from(_source.getProblemMark()); } }
public Mark getProblemMark() { return Mark.from(_source.getProblemMark()); } }
public ParsingError(ErrorCode errorCode, MarkedYAMLException cause) { this(ParsingErrorLevel.ERROR, errorCode, cause.getContext(), cause.getContextMark() != null ? cause.getContextMark() : cause.getProblemMark(), cause.getProblem(), cause.getProblemMark(), null); } }
public YamlSyntaxErrorException(String message, MarkedYAMLException cause) { super(cause.getContext(), cause.getContextMark(), message, cause.getProblemMark()); }
private static String formatYamlExceptionMessage(Resource res, YAMLException ye) { final StringBuilder sb = new StringBuilder(); sb.append("YAML parsing error in ").append(res); if (ye instanceof MarkedYAMLException) { final Mark mark = ((MarkedYAMLException) ye).getProblemMark(); final String snippet = mark != null ? mark.get_snippet() : null; final String problem = ((MarkedYAMLException) ye).getProblem(); if (mark != null) { sb.append(" at line ").append(mark.getLine()).append(", column ").append(mark.getColumn()); } if (snippet != null) { sb.append(":\n"); sb.append(snippet); } if (problem != null) { // TODO SnakeYaml tends to be a bit nasty about this "problem", e.g org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens() prints the actual char THEN it's representation, so you end up with a big fat actual tab in the message instead of JUST \t(TAB) // See https://code.google.com/p/snakeyaml/issues/detail?id=209 sb.append(": ").append(problem.replaceAll("\\s*\\t\\s*", " ")); } } else { sb.append(": ").append(ye.getMessage()); } return sb.toString(); } }
public static SwaggerError newYamlError(YAMLException exception) { int line = (exception instanceof MarkedYAMLException) ? ((MarkedYAMLException) exception).getProblemMark().getLine() + 1 : 1; return new SwaggerError(line, IMarker.SEVERITY_ERROR, 0, processor.rewriteMessage(exception)); }
errorMessage.add(createErrorResult(mye.getProblem(), mye.getProblemMark(), mye.getProblemMark()));
public MarkedYAMLException apply(MarkedYAMLException e, String yaml) throws IOException { Mark problemMark = e.getProblemMark(); Optional<YamlLine> prevLine = getLine(yaml, problemMark.getLine() - 1); Optional<YamlLine> line = getLine(problemMark.get_snippet(0, 100), 0); if (prevLine.isPresent() && line.isPresent()) { YamlLine prev = prevLine.get(); YamlLine current = line.get(); if (isIncorrectIndentation(prev, current)) { return incorrectIndentationException(prev, current, e); } else if (isItemOutsideSequence(prev, current)) { return itemOutsideSequence(e); } } return new YamlSyntaxErrorException(e.getMessage(), e); }
private static Node buildYamlErrorNode(MarkedYAMLException e, String resourcePath) { final ErrorNode errorNode = new ErrorNode("Underlying error while parsing YAML syntax: '" + e.getMessage() + "'"); final Mark problemMark = e.getProblemMark(); errorNode.setStartPosition(new DefaultPosition(problemMark.getIndex(), problemMark.getLine(), 0, resourcePath, new DefaultResourceLoader())); errorNode.setEndPosition(new DefaultPosition(problemMark.getIndex() + 1, problemMark.getLine(), problemMark.getColumn(), resourcePath, new DefaultResourceLoader())); return errorNode; }
private static void raiseParserException(ThreadContext context, IRubyObject yaml, MarkedYAMLException mye, IRubyObject rbPath) { Ruby runtime; Mark mark; RubyClass se; IRubyObject exception; runtime = context.runtime; se = (RubyClass)runtime.getModule("Psych").getConstant("SyntaxError"); mark = mye.getProblemMark(); exception = se.newInstance(context, new IRubyObject[] { rbPath, runtime.newFixnum(mark.getLine() + 1), runtime.newFixnum(mark.getColumn() + 1), runtime.newFixnum(mark.getIndex()), (null == mye.getProblem() ? runtime.getNil() : runtime.newString(mye.getProblem())), (null == mye.getContext() ? runtime.getNil() : runtime.newString(mye.getContext())) }, Block.NULL_BLOCK); RubyKernel.raise(context, runtime.getKernel(), new IRubyObject[] { exception }, Block.NULL_BLOCK); }
private static void raiseParserException(ThreadContext context, IRubyObject yaml, MarkedYAMLException mye, IRubyObject rbPath) { Ruby runtime; Mark mark; RubyClass se; IRubyObject exception; runtime = context.runtime; se = (RubyClass)runtime.getModule("Psych").getConstant("SyntaxError"); mark = mye.getProblemMark(); exception = se.newInstance(context, new IRubyObject[] { rbPath, runtime.newFixnum(mark.getLine() + 1), runtime.newFixnum(mark.getColumn() + 1), runtime.newFixnum(mark.getIndex()), (null == mye.getProblem() ? runtime.getNil() : runtime.newString(mye.getProblem())), (null == mye.getContext() ? runtime.getNil() : runtime.newString(mye.getContext())) }, Block.NULL_BLOCK); RubyKernel.raise(context, runtime.getKernel(), new IRubyObject[] { exception }, Block.NULL_BLOCK); }