goog.provide('scittle.impl.error');
scittle.impl.error.println = (function scittle$impl$error$println(var_args){
var args__5755__auto__ = [];
var len__5749__auto___49965 = arguments.length;
var i__5750__auto___49966 = (0);
while(true){
if((i__5750__auto___49966 < len__5749__auto___49965)){
args__5755__auto__.push((arguments[i__5750__auto___49966]));

var G__49967 = (i__5750__auto___49966 + (1));
i__5750__auto___49966 = G__49967;
continue;
} else {
}
break;
}

var argseq__5756__auto__ = ((((0) < args__5755__auto__.length))?(new cljs.core.IndexedSeq(args__5755__auto__.slice((0)),(0),null)):null);
return scittle.impl.error.println.cljs$core$IFn$_invoke$arity$variadic(argseq__5756__auto__);
});

(scittle.impl.error.println.cljs$core$IFn$_invoke$arity$variadic = (function (strs){
return console.error(clojure.string.join.cljs$core$IFn$_invoke$arity$2(" ",strs));
}));

(scittle.impl.error.println.cljs$lang$maxFixedArity = (0));

/** @this {Function} */
(scittle.impl.error.println.cljs$lang$applyTo = (function (seq49899){
var self__5735__auto__ = this;
return self__5735__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq49899));
}));

scittle.impl.error.ruler = (function scittle$impl$error$ruler(title){
return scittle.impl.error.println.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([cljs.core.apply.cljs$core$IFn$_invoke$arity$5(cljs.core.str,"----- ",title," ",cljs.core.repeat.cljs$core$IFn$_invoke$arity$2((((50) - (7)) - cljs.core.count(title)),"-"))], 0));
});
scittle.impl.error.split_stacktrace = (function scittle$impl$error$split_stacktrace(stacktrace,verbose_QMARK_){
if(cljs.core.truth_(verbose_QMARK_)){
return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [stacktrace], null);
} else {
var stack_count = cljs.core.count(stacktrace);
if((stack_count <= (10))){
return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [stacktrace], null);
} else {
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.take.cljs$core$IFn$_invoke$arity$2((5),stacktrace),cljs.core.drop.cljs$core$IFn$_invoke$arity$2((stack_count - (5)),stacktrace)], null);
}
}
});
scittle.impl.error.print_stacktrace = (function scittle$impl$error$print_stacktrace(stacktrace,p__49913){
var map__49914 = p__49913;
var map__49914__$1 = cljs.core.__destructure_map(map__49914);
var verbose_QMARK_ = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__49914__$1,new cljs.core.Keyword(null,"verbose?","verbose?",1244836832));
var stacktrace__$1 = sci.core.format_stacktrace(stacktrace);
var segments = scittle.impl.error.split_stacktrace(stacktrace__$1,verbose_QMARK_);
var vec__49915 = segments;
var fst = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__49915,(0),null);
var snd = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__49915,(1),null);
cljs.core.run_BANG_((function (p1__49910_SHARP_){
return cljs.core.print.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([p1__49910_SHARP_,"\n"], 0));
}),fst);

if(cljs.core.truth_(snd)){
cljs.core.print.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["...\n"], 0));

return cljs.core.run_BANG_((function (p1__49911_SHARP_){
return cljs.core.print.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([p1__49911_SHARP_,"\n"], 0));
}),snd);
} else {
return null;
}
});
scittle.impl.error.error_context = (function scittle$impl$error$error_context(ex,src_map){
var map__49928 = cljs.core.ex_data(ex);
var map__49928__$1 = cljs.core.__destructure_map(map__49928);
var file = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__49928__$1,new cljs.core.Keyword(null,"file","file",-1269645878));
var line = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__49928__$1,new cljs.core.Keyword(null,"line","line",212345235));
var column = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__49928__$1,new cljs.core.Keyword(null,"column","column",2078222095));
if(cljs.core.truth_((function (){var and__5023__auto__ = file;
if(cljs.core.truth_(and__5023__auto__)){
return line;
} else {
return and__5023__auto__;
}
})())){
var temp__5804__auto__ = cljs.core.get.cljs$core$IFn$_invoke$arity$2(src_map,file);
if(cljs.core.truth_(temp__5804__auto__)){
var content = temp__5804__auto__;
var matching_line = (line - (1));
var start_line = (function (){var x__5110__auto__ = (matching_line - (4));
var y__5111__auto__ = (0);
return ((x__5110__auto__ > y__5111__auto__) ? x__5110__auto__ : y__5111__auto__);
})();
var end_line = (matching_line + (6));
var vec__49930 = cljs.core.split_at(((matching_line - start_line) + (1)),cljs.core.take.cljs$core$IFn$_invoke$arity$2((end_line - start_line),cljs.core.drop.cljs$core$IFn$_invoke$arity$2(start_line,cljs.core.map_indexed.cljs$core$IFn$_invoke$arity$2(cljs.core.list,clojure.string.split_lines(content)))));
var before = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__49930,(0),null);
var after = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__49930,(1),null);
var snippet_lines = cljs.core.concat.cljs$core$IFn$_invoke$arity$variadic(before,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [null,[clojure.string.join.cljs$core$IFn$_invoke$arity$2("",cljs.core.repeat.cljs$core$IFn$_invoke$arity$2((column - (1))," ")),["^--- ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.ex_message(ex))].join('')].join('')], null)], null),cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([after], 0));
var indices = cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.first,snippet_lines);
var max_size = cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.max,(0),cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.comp.cljs$core$IFn$_invoke$arity$2(cljs.core.count,cljs.core.str),indices));
var snippet_lines__$1 = cljs.core.map.cljs$core$IFn$_invoke$arity$2((function (p__49940){
var vec__49942 = p__49940;
var idx = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__49942,(0),null);
var line__$1 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__49942,(1),null);
if(cljs.core.truth_(idx)){
var line_number = (idx + (1));
return [cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.str.cljs$core$IFn$_invoke$arity$1(line_number).padStart(max_size,"0")),"  ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(line__$1)].join('');
} else {
return [clojure.string.join.cljs$core$IFn$_invoke$arity$1(cljs.core.repeat.cljs$core$IFn$_invoke$arity$2(((2) + max_size)," ")),cljs.core.str.cljs$core$IFn$_invoke$arity$1(line__$1)].join('');
}
}),snippet_lines);
return ["\n",clojure.string.join.cljs$core$IFn$_invoke$arity$2("\n",snippet_lines__$1)].join('');
} else {
return null;
}
} else {
return null;
}
});
scittle.impl.error.right_pad = (function scittle$impl$error$right_pad(s,n){
var n__$1 = (n - cljs.core.count(s));
return [cljs.core.str.cljs$core$IFn$_invoke$arity$1(s),clojure.string.join.cljs$core$IFn$_invoke$arity$1(cljs.core.repeat.cljs$core$IFn$_invoke$arity$2(n__$1," "))].join('');
});
scittle.impl.error.error_handler = (function scittle$impl$error$error_handler(e,src_map){
var d = cljs.core.ex_data(e);
var sci_error_QMARK_ = cljs.core.isa_QMARK_.cljs$core$IFn$_invoke$arity$2(new cljs.core.Keyword(null,"type","type",1174270348).cljs$core$IFn$_invoke$arity$1(d),new cljs.core.Keyword("sci","error","sci/error",-979082803));
var stacktrace = sci.core.stacktrace(e);
scittle.impl.error.ruler("Scittle error");

var temp__5804__auto___49975 = e.name;
if(cljs.core.truth_(temp__5804__auto___49975)){
var name_49976 = temp__5804__auto___49975;
if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2("Error",name_49976)){
} else {
scittle.impl.error.println.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["Type:    ",name_49976], 0));
}
} else {
}

var temp__5804__auto___49978 = e.message;
if(cljs.core.truth_(temp__5804__auto___49978)){
var m_49979 = temp__5804__auto___49978;
scittle.impl.error.println.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([["Message:  ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(m_49979)].join('')], 0));
} else {
}

var temp__5804__auto___49980 = cljs.core.ex_data(cljs.core.ex_cause(e));
if(cljs.core.truth_(temp__5804__auto___49980)){
var d_49981__$1 = temp__5804__auto___49980;
scittle.impl.error.println.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["Data:     ",cljs.core.pr_str.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([d_49981__$1], 0))], 0));
} else {
}

var map__49953_49982 = d;
var map__49953_49983__$1 = cljs.core.__destructure_map(map__49953_49982);
var file_49984 = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__49953_49983__$1,new cljs.core.Keyword(null,"file","file",-1269645878));
var line_49985 = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__49953_49983__$1,new cljs.core.Keyword(null,"line","line",212345235));
var column_49986 = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__49953_49983__$1,new cljs.core.Keyword(null,"column","column",2078222095));
if(cljs.core.truth_(line_49985)){
scittle.impl.error.println.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([["Location: ",(cljs.core.truth_(file_49984)?[cljs.core.str.cljs$core$IFn$_invoke$arity$1(file_49984),":"].join(''):null),cljs.core.str.cljs$core$IFn$_invoke$arity$1(line_49985),":",cljs.core.str.cljs$core$IFn$_invoke$arity$1(column_49986),""].join('')], 0));
} else {
}

var temp__5804__auto___49987 = new cljs.core.Keyword(null,"phase","phase",575722892).cljs$core$IFn$_invoke$arity$1(d);
if(cljs.core.truth_(temp__5804__auto___49987)){
var phase_49988 = temp__5804__auto___49987;
scittle.impl.error.println.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["Phase:   ",phase_49988], 0));
} else {
}

var temp__5804__auto___49989 = ((sci_error_QMARK_)?scittle.impl.error.error_context(e,src_map):null);
if(cljs.core.truth_(temp__5804__auto___49989)){
var ec_49991 = temp__5804__auto___49989;
scittle.impl.error.ruler("Context");

scittle.impl.error.println.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([ec_49991], 0));
} else {
}

if(sci_error_QMARK_){
var temp__5804__auto__ = (function (){var st = (function (){var sb__5670__auto__ = (new goog.string.StringBuffer());
var _STAR_print_newline_STAR__orig_val__49956_49995 = cljs.core._STAR_print_newline_STAR_;
var _STAR_print_fn_STAR__orig_val__49957_49996 = cljs.core._STAR_print_fn_STAR_;
var _STAR_print_newline_STAR__temp_val__49958_49997 = true;
var _STAR_print_fn_STAR__temp_val__49959_49998 = (function (x__5671__auto__){
return sb__5670__auto__.append(x__5671__auto__);
});
(cljs.core._STAR_print_newline_STAR_ = _STAR_print_newline_STAR__temp_val__49958_49997);

(cljs.core._STAR_print_fn_STAR_ = _STAR_print_fn_STAR__temp_val__49959_49998);

try{if(cljs.core.truth_(stacktrace)){
scittle.impl.error.print_stacktrace(stacktrace,src_map);
} else {
}
}finally {(cljs.core._STAR_print_fn_STAR_ = _STAR_print_fn_STAR__orig_val__49957_49996);

(cljs.core._STAR_print_newline_STAR_ = _STAR_print_newline_STAR__orig_val__49956_49995);
}
return cljs.core.str.cljs$core$IFn$_invoke$arity$1(sb__5670__auto__);
})();
if(clojure.string.blank_QMARK_(st)){
return null;
} else {
return st;
}
})();
if(cljs.core.truth_(temp__5804__auto__)){
var st = temp__5804__auto__;
scittle.impl.error.ruler("Stack trace");

return scittle.impl.error.println.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([st], 0));
} else {
return null;
}
} else {
return null;
}
});

//# sourceMappingURL=scittle.impl.error.js.map
