Skip to content

Commit

Permalink
Use try/catch for throw
Browse files Browse the repository at this point in the history
  • Loading branch information
fel1x-developer committed Mar 30, 2024
1 parent 98e0579 commit d331632
Show file tree
Hide file tree
Showing 5 changed files with 1,443 additions and 35 deletions.
75 changes: 40 additions & 35 deletions src/share/poudriere/html/assets/poudriere.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,43 +481,48 @@ function formatStatusRow(status, row, n) {
const tableRow = [];

tableRow.push(n + 1);
if (status === 'built') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
tableRow.push(formatLog(row.pkgname, false, 'success'));
tableRow.push(formatDuration(row.elapsed ? row.elapsed : ''));
} else if (status === 'failed') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
tableRow.push(row.phase);
tableRow.push(row.skipped_cnt);
tableRow.push(formatLog(row.pkgname, true, row.errortype));
tableRow.push(formatDuration(row.elapsed ? row.elapsed : ''));
} else if (status === 'skipped') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
tableRow.push(formatPkgName(row.depends));
} else if (status === 'ignored') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
tableRow.push(row.skipped_cnt);
tableRow.push(row.reason);
} else if (status === 'fetched') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
} else if (status === 'remaining') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(row.status);
} else if (status === 'queued') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
if (row.reason === 'listed') {

try {
if (status === 'built') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
tableRow.push(formatLog(row.pkgname, false, 'success'));
tableRow.push(formatDuration(row.elapsed ? row.elapsed : ''));
} else if (status === 'failed') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
tableRow.push(row.phase);
tableRow.push(row.skipped_cnt);
tableRow.push(formatLog(row.pkgname, true, row.errortype));
tableRow.push(formatDuration(row.elapsed ? row.elapsed : ''));
} else if (status === 'skipped') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
tableRow.push(formatPkgName(row.depends));
} else if (status === 'ignored') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
tableRow.push(row.skipped_cnt);
tableRow.push(row.reason);
} else if (status === 'fetched') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
} else if (status === 'remaining') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(row.status);
} else if (status === 'queued') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
if (row.reason === 'listed') {
tableRow.push(row.reason);
} else {
tableRow.push(formatOrigin(row.reason));
}
} else {
tableRow.push(formatOrigin(row.reason));
throw new Error(`Unknown data type "${status}". Try flushing cache.`);
}
} else {
throw new Error(`Unknown data type "${status}". Try flushing cache.`);
} catch (err) {
console.error(err);
}

return tableRow;
Expand Down Expand Up @@ -1279,7 +1284,7 @@ function setupIndex() {
],
responsive: true,
rowGroup: {
dataSrc: ["ptname", "setname"],
dataSrc: ['ptname', 'setname'],
},
});

Expand Down
258 changes: 258 additions & 0 deletions src/share/poudriere/html/assets/poudriere/format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
'use strict';

import {
serverStyle, pageMasterName, pageBuildName, pageType, dataURL,
} from './poudriere';

export function jailURL(mastername) {
if (serverStyle === 'hosted') {
if (mastername) {
return `jail.html?mastername=${encodeURIComponent(mastername)}`;
}
return '#';
}
return '../';
}

export function buildURL(mastername, buildname) {
if (!mastername || !buildname) {
return '';
}
return (
'build.html?'
+ `mastername=${
encodeURIComponent(mastername)
}&`
+ `build=${
encodeURIComponent(buildname)}`
);
}

export function formatOrigin(origin, flavor) {
if (!origin) {
return '';
}

const data = origin.split('/');
let resultFlavor = '';

if (flavor) {
resultFlavor = `@${flavor}`;
} else {
resultFlavor = '';
}

return (
`<a target="_new" title="freshports for ${
origin
}" href="https://www.freshports.org/${
data[0]
}/${
data[1]
}/"><span `
+ `class="glyphicon glyphicon-tasks"></span>${
origin
}${resultFlavor
}</a>`
);
}

export function formatPkgName(pkgname) {
return pkgname;
}

export function formatMasterName(mastername) {
let html;

if (!mastername) {
return '';
}

if (pageMasterName && mastername === pageMasterName && pageType === 'jail') {
html = `<a href="#top" onclick="scrollToElement('#top'); return false;">${
mastername
}</a>`;
} else {
html = `<a title="List builds for ${
mastername
}" href="${
jailURL(mastername)
}">${
mastername
}</a>`;
}

return html;
}

export function formatJailName(jailname) {
return jailname;
}

export function formatSetName(setname) {
return setname;
}

export function formatPtName(ptname) {
return ptname;
}

export function formatBuildName(mastername, buildname) {
let html;

if (!mastername) {
return buildname;
} if (!buildname) {
return '';
}

if (
pageMasterName
&& mastername === pageMasterName
&& pageBuildName
&& buildname === pageBuildName
&& pageType === 'build'
) {
html = `<a href="#top" onclick="scrollToElement('#top'); return false;">${
buildname
}</a>`;
} else {
html = `<a title="Show build results for ${
buildname
}" href="${
buildURL(mastername, buildname)
}">${
buildname
}</a>`;
}

return html;
}

export function formatPortSet(ptname, setname) {
return ptname + (setname ? '-' : '') + setname;
}

export function formatLog(pkgname, errors, text) {
const html = `<a target="logs" title="Log for ${
pkgname
}" href="${
dataURL
}logs/${
errors ? 'errors/' : ''
}${pkgname
}.log"><span class="glyphicon glyphicon-file"></span>${
text
}</a>`;
return html;
}

function formatDuration(duration) {
let hours; let minutes; let
seconds;

if (duration === undefined || duration === '' || Number.isNaN(duration)) {
return '';
}

hours = Math.floor(duration / 3600);
const tmpDuration = duration - hours * 3600;
minutes = Math.floor(tmpDuration / 60);
seconds = tmpDuration - minutes * 60;

if (hours < 10) {
hours = `0${hours}`;
}
if (minutes < 10) {
minutes = `0${minutes}`;
}
if (seconds < 10) {
seconds = `0${seconds}`;
}

return `${hours}:${minutes}:${seconds}`;
}

export function formatStartToEnd(start, end) {
let duration;

if (!start) {
return '';
}
const startStr = parseInt(start, 10);
if (Number.isNaN(startStr)) {
return '';
}

if (end === undefined) {
duration = startStr;
} else {
duration = end - startStr;
}

if (duration < 0) {
duration = 0;
}

return formatDuration(duration);
}

export function formatSkipped(skippedCnt, pkgname) {
if (skippedCnt === undefined || skippedCnt === 0) {
return 0;
}
return (
`<a href="#skipped" onclick="filterSkipped('${
pkgname
}'); return false;"><span class="glyphicon `
+ `glyphicon-filter"></span>${
skippedCnt
}</a>`
);
}

export function formatStatusRow(status, row, n) {
const tableRow = [];

tableRow.push(n + 1);
if (status === 'built') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
tableRow.push(formatLog(row.pkgname, false, 'success'));
tableRow.push(formatDuration(row.elapsed ? row.elapsed : ''));
} else if (status === 'failed') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
tableRow.push(row.phase);
tableRow.push(row.skipped_cnt);
tableRow.push(formatLog(row.pkgname, true, row.errortype));
tableRow.push(formatDuration(row.elapsed ? row.elapsed : ''));
} else if (status === 'skipped') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
tableRow.push(formatPkgName(row.depends));
} else if (status === 'ignored') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
tableRow.push(row.skipped_cnt);
tableRow.push(row.reason);
} else if (status === 'fetched') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
} else if (status === 'remaining') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(row.status);
} else if (status === 'queued') {
tableRow.push(formatPkgName(row.pkgname));
tableRow.push(formatOrigin(row.origin, row.flavor));
if (row.reason === 'listed') {
tableRow.push(row.reason);
} else {
tableRow.push(formatOrigin(row.reason));
}
} else {
throw new Error(`Unknown data type "${status}". Try flushing cache.`);
}

return tableRow;
}
Loading

0 comments on commit d331632

Please sign in to comment.