Skip to content

Commit

Permalink
Better error log
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomatiasgomez committed Nov 14, 2023
1 parent 01a6d34 commit 834b986
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions js/guarani/PagesDataParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ UtnBaHelper.PagesDataParser = function (utils) {
if ($table.find(".alert").text().trim() === "No hay definidas correlativas para la actividad") return dependencies;

let elems = $table.children().toArray();
if (elems.length % 4 !== 0) throw new Error(`invalid contents: ${elems.length}`);
if (elems.length % 4 !== 0) throw new Error(`invalid contents: ${elems.length}. responseCont: ${response.cont}`);

for (let i = 0; i < elems.length; i += 4) {
// There are 4 elements per each kind:
Expand All @@ -186,23 +186,23 @@ UtnBaHelper.PagesDataParser = function (utils) {
// 4. table with dependencies
let kindTxt = $(elems[i]).find("> div > h3").text();
let kind = kindsMapping[kindTxt];
if (!kind) throw new Error(`Invalid kind ${kindTxt}`);
if (!kind) throw new Error(`Invalid kind ${kindTxt}. responseCont: ${response.cont}`);

if ($(elems[i + 2]).filter("h4").text() !== "Opción 1") throw new Error(`Don't know how to handle other options: ${$(elems[i + 2]).filter("h4").text()}`);
if ($(elems[i + 2]).filter("h4").text() !== "Opción 1") throw new Error(`Don't know how to handle other options: ${$(elems[i + 2]).filter("h4").text()}. responseCont: ${response.cont}`);

// Filter for "table" just in case.
$(elems[i + 3]).filter("table").find("tr:not(:first)").toArray().forEach(tr => {
let $tr = $(tr);

let dependencyCourse = $tr.find("td:eq(0)").text().trim();
let groups = /^(.*) \((\d{6})\)$/.exec(dependencyCourse);
if (!groups) throw new Error(`requirementTxt couldn't be parsed: ${dependencyCourse}`);
if (!groups) throw new Error(`requirementTxt couldn't be parsed: ${dependencyCourse}. responseCont: ${response.cont}`);
// let courseName = groups[1];
let dependencyCourseCode = groups[2];

let requirementTxt = $tr.find("td:eq(1)").text().trim();
let requirement = requirementMapping[requirementTxt];
if (!requirement) throw new Error(`requirementTxt couldn't be parsed: ${requirementTxt}`);
if (!requirement) throw new Error(`requirementTxt couldn't be parsed: ${requirementTxt}. responseCont: ${response.cont}`);

dependencies.push({
kind: kind,
Expand All @@ -223,7 +223,7 @@ UtnBaHelper.PagesDataParser = function (utils) {
// PlanCode
let planText = $contents.find(".encabezado").find("td:eq(1)").text();
let groups = /^Plan: \((\w+)\)/.exec(planText);
if (!groups) throw new Error(`planText couldn't be parsed: ${planText}`);
if (!groups) throw new Error(`planText couldn't be parsed: ${planText}. responseText: ${responseText}`);
let planCode = groups[1];

// Courses
Expand Down Expand Up @@ -252,7 +252,7 @@ UtnBaHelper.PagesDataParser = function (utils) {
return $accordion.find("table:first tbody tr:not(.correlatividades)").toArray().map(courseRow => {
let courseText = courseRow.querySelector("td").innerText.trim();
let groups = /(.*) \((\d{6})\)/.exec(courseText);
if (!groups) throw new Error(`courseText couldn't be parsed: ${courseText}.`);
if (!groups) throw new Error(`courseText couldn't be parsed: ${courseText}. responseText: ${responseText}`);
let courseName = groups[1];
let courseCode = groups[2];

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "UTN.BA Helper (ex Siga Helper)",
"short_name": "UTN.BA Helper",
"version": "6.4.1",
"version": "6.4.2",
"description": "UTN.BA Helper facilita el uso de la web de la UTN - FRBA.",
"author": "Pablo Matías Gomez",
"icons": {
Expand Down

0 comments on commit 834b986

Please sign in to comment.