package alien4cloud.tosca.parser;

import lombok.Getter;
import lombok.Setter;

import org.yaml.snakeyaml.error.Mark;
import org.yaml.snakeyaml.error.MarkedYAMLException;

import alien4cloud.tosca.parser.impl.ErrorCode;

/**
 * Contains error informations relative to Yaml parsing.
 */
@Getter
@Setter
public class ParsingError {
    private ParsingErrorLevel errorLevel;
    private ErrorCode errorCode;
    private String context;
    private SimpleMark startMark;
    private String problem;
    private SimpleMark endMark;
    private String note;

    public ParsingError() {
    }

    public ParsingError(ParsingErrorLevel errorLevel, ErrorCode errorCode, String context, Mark startMark, String problem, Mark endMark, String note) {
        this.errorLevel = errorLevel;
        this.errorCode = errorCode;
        this.context = context;
        this.startMark = startMark == null ? null : new SimpleMark(startMark);
        this.problem = problem;
        this.endMark = endMark == null ? null : new SimpleMark(endMark);
        this.note = note;
    }

    public ParsingError(ErrorCode errorCode, String context, Mark startMark, String problem, Mark endMark, String note) {
        this.errorLevel = ParsingErrorLevel.ERROR;
        this.errorCode = errorCode;
        this.context = context;
        this.startMark = startMark == null ? null : new SimpleMark(startMark);
        this.problem = problem;
        this.endMark = endMark == null ? null : new SimpleMark(endMark);
        this.note = note;
    }

    public ParsingError(ErrorCode errorCode, MarkedYAMLException cause) {
        this.errorLevel = ParsingErrorLevel.ERROR;
        this.errorCode = errorCode;
        this.context = cause.getContext();
        this.startMark = cause.getContextMark() == null ? null : new SimpleMark(cause.getContextMark());
        this.problem = cause.getProblem();
        this.endMark = cause.getContextMark() == null ? null : new SimpleMark(cause.getProblemMark());
        this.note = null;
    }

    @Override
    public String toString() {
        return "Context: " + context + "\nProblem: " + problem + "\nNote: " + note + "\nStart: " + startMark + "\nEnd  : " + endMark;
    }
}
@@ -71,16 +71,50 @@
 .Setter;
+%0Aimport lombok.extern.slf4j.Slf4j;
 %0A%0Aimport
@@ -329,16 +329,23 @@
 @Setter%0A
+@Slf4j%0A
 public c
@@ -1082,32 +1082,272 @@
 is.note = note;%0A
+        if (errorLevel == ParsingErrorLevel.ERROR) %7B%0A            // this is a handy place to put a breakpoint if you want to know where errors are coming from%0A            log.debug(%22Error found during parse, rethrowing:%5Cn%22+this);%0A        %7D%0A
     %7D%0A%0A    publi
@@ -1467,38 +1467,25 @@
         this
-.errorLevel = 
+(
 ParsingError
@@ -1499,286 +1499,64 @@
 RROR
-;%0A        this.errorCode = errorCode;%0A        this.context = context;%0A        this.startMark = startMark == null ? null : new SimpleMark(startMark);%0A        this.problem = problem;%0A        this.endMark = endMark == null ? null : new SimpleMark(endMark);%0A        this.note = note
+, errorCode, context, startMark, problem, endMark, note)
 ;%0A  
@@ -1646,30 +1646,17 @@
     this
-.errorLevel = 
+(
 ParsingE
@@ -1674,364 +1674,114 @@
 RROR
-;%0A        this.errorCode = errorCode;%0A        this.context = cause.getContext();%0A        this.startMark = cause.getContextMark() == null ? null : new SimpleMark(cause.getContextMark());%0A        this.problem = cause.getProblem();%0A        this.endMark = cause.getContextMark() == null ? null : new SimpleMark(cause.getProblemMark());%0A        this.note =
+, errorCode, cause.getContext(), cause.getContextMark(), cause.getProblem(), cause.getProblemMark(),
  null
+)
 ;%0A  

make ParsingError re-use code and easier to breakpoint