%%decl using namespace std; <%impl> #include #include #include #include #include #include #include #include #include #include #include #include %%var string message; %%var string root_source; %%var string root_intermediate; %%var string root_so; %%var string component; %%var int line_number = -1; %%var const exception* exception_caught; <%code> __SCIF->headers.clear(); __SCIF->out->seekp(0); int magic = _magic; va_list va = _args; switch(magic) { case sitecing::__magic_compile_error: message = va_arg(va,const char*); root_source = va_arg(va,const char*); root_intermediate = va_arg(va,const char*); root_so = va_arg(va,const char*); component = va_arg(va,const char*); break; case sitecing::__magic_preprocess_error: message = va_arg(va,const char*); root_source = va_arg(va,const char*); root_intermediate = va_arg(va,const char*); root_so = va_arg(va,const char*); component = va_arg(va,const char*); line_number = va_arg(va,int); break; case sitecing::__magic_generic_exception: message = va_arg(va,const char*); root_source = va_arg(va,const char*); root_intermediate = va_arg(va,const char *); root_so = va_arg(va,const char *); component = va_arg(va,const char*); exception_caught = va_arg(va,const exception*); break; default: break; } <% message %> % __SCIF->headers["Content-Type"]="text/html; charset=utf-8"; % __SCIF->headers["Pragma"]="no-cache"; <%code> switch(magic) { case sitecing::__magic_compile_error: handle_compile_error(); break; case sitecing::__magic_preprocess_error: handle_preprocess_error(); break; case sitecing::__magic_generic_exception: handle_generic_exception(); break; default: handle_unknown_error(); break; }
Powered by site-C-ing.
<%method void handle_generic_exception() %>

exception caught while running component '<% component %>'

typeid(e).name()
% int destat; % char *demangled = abi::__cxa_demangle(typeid(*exception_caught).name(),NULL,NULL,&destat);
<% destat?typeid(*exception_caught).name():demangled %>
% if(!destat) free(demangled);
e.what()
<% message %>
% if(typeid(*exception_caught)==typeid(konforka::exception&)) { % konforka::exception* ke = (konforka::exception*)exception_caught;
e.where()
% if(ke->_where.line<0) { <% ke->where() %> % }else{ <% strip_roots(ke->_where.file) %>:<% ke->_where.line %> [<% ke->_where.function %>] % }
% }
% if(typeid(*exception_caught)==typeid(konforka::exception&)) { % konforka::exception* ke = (konforka::exception*)exception_caught; % if(ke->_where.line>=0) { % report_error(ke->_where.file,ke->_where.line,ke->what()); % } % if(!ke->_seen.empty()) {

seen at:

% for(list::const_iterator i=ke->_seen.begin();i!=ke->_seen.end();++i) { % if(i->line>=0) { % report_error(i->file,i->line,i->function); % } % }
% } % }
<%method void handle_preprocess_error() %>

error preprocessing component '<% component %>'

% report_error(root_source+component,line_number,message);
<%method void handle_compile_error() %>

error compiling component '<% component %>'

<%code> ifstream err((root_intermediate+component+".stderr").c_str(),ios::in); if(err.bad()) { <%output> Failed to access compiler output }else{ string cumulative; string error_file; long error_line = -1; while(!err.eof()) { string oef = error_file; long oel = error_line; string line; getline(err,line); if(line[0]!=' ') { string::size_type c = line.find(':'); if(c!=string::npos) { string fn = line.substr(0,c); string::size_type c1 = line.find(':',c+1); if(c1!=string::npos) { string ln = line.substr(c+1,c1-c-1); string::size_type nd = ln.find_first_not_of("0123456789"); if(nd==string::npos) { try { error_file = sitecing::strip_prefix(fn,"In file included from "); }catch(sitecing::utility_no_prefix& unp) { error_file = fn; } error_line = strtol(ln.c_str(),0,10); } } } if((oel>0 && !oef.empty()) && (oel!=error_line || oef!=error_file)) { string ef = "/"+konforka::combine_path(root_source+component,oef); report_error(ef,oel,remove_roots(cumulative)); cumulative.clear(); } } if(!cumulative.empty()) cumulative += '\n'; cumulative += line; } if(!(cumulative.empty() || error_file.empty() || error_line<0)) { error_file = "/"+konforka::combine_path(root_source+component,error_file); report_error(error_file,error_line,remove_roots(cumulative)); } }
<%method void handle_unknown_error() %>

unknown error

<%method void report_error(const string& file,long line,const string& message) %>

<% sitecing::html_escape(strip_roots(file)) %>

<%code> if(line>=0) { int firstline = line-5, lastline = line+5; if(firstline<1) firstline = 1; ifstream ifs(file.c_str(),ios::in); if(ifs.bad()) { // TODO: }else{ for(int l=1;l
    for(int l=firstline;l<=lastline && !ifs.eof();l++) { string str; getline(ifs,str); for(string::size_type t=str.find('\t');t!=string::npos;t=str.find('\t')) { str.replace(t,1,8-(t%8),' '); } char tln[16]; snprintf(tln,sizeof(tln),"%5d",l); <%output>
  • "><% sitecing::html_escape(tln,sitecing::html_escape_nbsp) %> <% sitecing::html_escape(str,sitecing::html_escape_nbsp) %>
  • } <%output>
} } }
<% sitecing::html_escape(message,sitecing::html_escape_br) %>
<%codemethod string strip_roots(const string& filename) %> string np = konforka::normalize_path(filename); try{ return sitecing::strip_prefix(np,root_source); }catch(sitecing::utility_no_prefix& e){ } try{ return sitecing::strip_prefix(np,root_intermediate); }catch(sitecing::utility_no_prefix& e){ } <%codemethod string remove_roots(const string& str) %> string rv = str; string::size_type rp; string::size_type rl = root_source.length(); while((rp=rv.find(root_source))!=string::npos) { rv.erase(rp,rl); } rl = root_intermediate.length(); while((rp=rv.find(root_intermediate))!=string::npos) { rv.erase(rp,rl); } rl = root_so.length(); while((rp=rv.find(root_so))!=string::npos) { rv.erase(rp,rl); } return rv; % /* vim:set ft=sitecing: */