Worked on exception reporting.

This commit is contained in:
Brad Arant 2024-09-25 17:15:03 -07:00
parent 387203f4b3
commit e655173a8f
7 changed files with 86 additions and 69 deletions

View File

@ -1,10 +1,21 @@
#include "__jet.h"
#include "Exception.h"
#include <iostream>
namespace jet {
__jet::__jet(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
processContainer(container);
try {
processContainer(container);
}
catch(coreutils::Exception e) {
std::cout << container.parsed() << std::endl;
std::cout << "***** " << e.text << std::endl;
std::cout << container.unparsed() << std::endl;
throw e;
}
}
}

View File

@ -21,7 +21,10 @@ namespace jet {
mysql = mysql_init(NULL);
mysql = mysql_real_connect(mysql, variables["host"].c_str(), variables["user"].c_str(), variables["password"].c_str(), variables["database"].c_str(), 0, NULL, 0);
if(!mysql)
throw coreutils::Exception("database and host parameters are not valid.");
std::cout << "mysql: " << mysql << std::endl;
processContainer(container);

View File

@ -17,8 +17,8 @@ do
done
wait
echo -n "Building executable testjet..."
g++ -g -o testjet $list -std=c++23 -L../CoreUtils -lCoreUtils -lmysqlclient
echo -n "Building executable jet-2.0..."
g++ -g -o jet-2.0 $list -std=c++23 -L../CoreUtils -lCoreUtils -lmysqlclient
if [ $? = '0' ]
then
echo "OK"

BIN
jet-2.0 Executable file

Binary file not shown.

26
jet-2.0.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <iostream>
#include <sstream>
#include "File.h"
#include "Global.h"
#include "Exception.h"
#include "__jet.h"
int main(int argc, char **argv) {
coreutils::File script(argv[1]);
script.read();
coreutils::ZString data = script.asZString();
data.goeol();
try {
jet::Global global;
coreutils::MString out;
jet::__jet *jet = new jet::__jet(data, out, global);
delete jet;
std::cout << out;
}
catch(coreutils::Exception e) {
std::cout << "Error caught: " << e.text << std::endl;
}
}

View File

@ -1,65 +0,0 @@
#include <iostream>
#include <sstream>
#include "Global.h"
#include "Exception.h"
#include "__jet.h"
int main(int argc, char **argv) {
coreutils::ZString data("<jet name1=\"localname\" filterblanklines=\"true\" trimlines=\"true\">\n"
" <comment>This is a comment and should not show up in the output.</comment>\n"
" <html>\n"
" $[nonexistant]\n"
" <mysql host=\"localhost\" database=\"barant\" user=\"barant\" password=\"uversa\" sessionid=\"1\">\n"
" <sql sessionid=\"1\">select * from testdata</sql>\n"
" $[1.text]\n"
" $[1.value]\n"
" </mysql>\n"
" <set name=\"ix\" value=\"1\" />\n"
" <set name=\"theexpr\" expr=\"SUBSTRING('abcdefg', 1, 3)\" />\n"
" <set name=\"theexpr2\" expr=\"5+3\" />\n"
" theexpr=($[theexpr])\n"
" theexpr2($[theexpr2])\n"
" <set name=\"varname$[ix]\" value=\"vardata\" scope=\"global\" />\n"
" <set name=\"noeval\" eval=\"no\">this is the value store in #[name].</set>\n"
" <set name=\"thename\" eval=\"yes\">this is the value store in #[name].</set>\n"
" <set name=\"newname\" scope=\"global\">another container value</set>\n"
" >>>$[noeval]<<<\n"
" >>>$[thename]<<<\n"
" <set name=\"iz\" value=\"data\" />\n"
" <set name=\"ix1\" value=\"1\" />\n"
" <set name=\"test$[ix$[ix1]]$[iz]\" value=\"0123456789\" />\n"
" $[test$[ix$[ix1]]$[iz]]\n"
" <if value1=\"X\" value2=\"Y\" type=\"ne\">\n"
" 789\n"
" <if expr=\"false\">\n"
" 123\n"
" <else>\n"
" 456\n"
" </if>\n"
" </if>\n"
" <for name=\"ix\" start=\"1\" end=\"5\" step=\"1\">\n"
" -->#[ix]<--\n"
" </for>\n"
" <call pgm=\"/usr/bin/ls\" arg1=\"-al\" name=\"ls\" />\n"
" $[lsi]\n"
" <read file=\"compile\" name=\"file\" />\n"
" $[filex]\n"
" </html>\n"
"</jet>\n");
std::cout << "---------\n" << data << "----------\n" << std::endl;
try {
jet::Global global;
coreutils::MString out;
jet::__jet *jet = new jet::__jet(data, out, global);
delete jet;
std::cout << ">>-------" << std::endl << out << "<<------" << std::endl;
// global.dump();
}
catch(coreutils::Exception e) {
std::cout << "Error caught: " << e.text << std::endl;
}
}

42
testjet.jet Executable file
View File

@ -0,0 +1,42 @@
#!./jet-2.0
<jet name1="localname" filterblanklines="true" trimlines="true">
<comment>This is a comment and should not show up in the output.</comment>
<html>
$[nonexistant]
<mysql host="localhost" database="barant" user="barant" password="uversa" sessionid="1">
<sql sessionid="1">select * from testdata</sql>
$[1.text]
$[1.value]
</mysql>
<set name="ix" value="1" />
<set name="theexpr" expr="SUBSTRING('abcdefg', 1, 3)" />
<set name=\"theexpr2\" expr=\"5+3\" />
theexpr=($[theexpr])
theexpr2($[theexpr2])
<set name="varname$[ix]" value="vardata" scope="global" />
<set name="noeval" eval="no">this is the value store in #[name].</set>
<set name="thename" eval="yes">this is the value store in #[name].</set>
<set name="newname" scope="global">another container value</set>
>>>$[noeval]<<<
>>>$[thename]<<<
<set name="iz" value="data" />
<set name="ix1" value="1" />
<set name="test$[ix$[ix1]]$[iz]" value="0123456789" />
$[test$[ix$[ix1]]$[iz]]
<if value1="X" value2="Y" type="ne">
789
<if expr="false">
123
<else>
456
</if>
</if>
<for name="ix" start="1" end="5" step="1">
-->#[ix]<--
</for>
<call pgm="/usr/bin/ls" arg1="-al" name="ls" />
$[lsi]
<read file="compile" name="file" />
$[filex]
</html>
</jet>