Commit 23b3baaa authored by Michael Pyne's avatar Michael Pyne

Merge branch 'mojo-err-checking' into 'make_it_mojo'

This is a series of small commits to improve error handling in our Mojolicious-based backend.

The biggest changes are to import the Mojolicious debug template (which handles both 404 and 500 HTTP errors), although we also create a dedicated log file for Mojolicious to use internally in the same log directory as used for other kdesrc-build logs that run.

A direction for future work is to integrate kdesrc-build's own logging system into Mojolicious's (so that there's only one way to do it).

See merge request !16  (I've gone ahead and self-approved after looking at it a second time since I won't have a lot of time during the upcoming work week)
parents 02e624fb 2c56ab7d
Pipeline #7592 passed with stage
in 1 minute and 25 seconds
......@@ -10,7 +10,7 @@ doc/*.docbook - Licensed per KDE Documentation policy, i.e. under the
Sections, no Front-Cover Texts, and no Back-Cover Texts.
Full text available as doc/COPYING.DOC
modules/web/public/sakura.css - Licensed under MIT License as noted in file.
modules/Mojo* (files and directories)
modules/Mojo*, modules/web/{templates,public}/mojo (files and directories)
- Licensed under Artistic License 2.0, see
https://github.com/mojolicious/mojo/raw/master/LICENSE
and modules/LICENSE.mojo
......
......@@ -56,6 +56,8 @@ sub new
{
my ($class, @options) = @_;
# TODO: Do something with @options
my $self = bless {
context => ksb::BuildContext->new(),
metadata_module => undef,
......@@ -450,9 +452,9 @@ sub establishContext
$ctx->setKDEDependenciesMetadataModuleNeeded();
$ctx->setKDEProjectsMetadataModuleNeeded();
if (!exists $ENV{HARNESS_ACTIVE}) {
# Running in a test harness, avoid downloading metadata which will be
# ignored in the test or making changes to git config
if (!exists $ENV{HARNESS_ACTIVE} && !$self->{run_mode} eq 'headless') {
# In some modes (testing, acting as headless backend), we should avoid
# downloading metadata automatically, so don't.
ksb::Updater::Git::verifyGitConfig();
$self->_downloadKDEProjectMetadata();
}
......
......@@ -36,9 +36,22 @@ sub make_new_ksb
chdir($c->app->{ksbhome});
my $app = ksb::Application->new->setHeadless;
# Note that we shouldn't /have/ any selectors at this point, it's now a
# separate user input.
my @selectors = $app->establishContext(@{$c->app->{options}});
$c->app->selectors([@selectors]);
$c->app->log->debug("Selectors are " . join(', ', @selectors));
# Reset log handler
my $ctx = $app->context();
$c->app->log(Mojo::Log->new(
path => $ctx->getLogDirFor($ctx) . "/mojo-backend.log"
));
if(@selectors) {
$c->app->log->info("Module selectors requested:" . join(', ', @selectors));
} else {
$c->app->log->info("All modules to be built");
}
return $app;
}
......@@ -109,22 +122,20 @@ sub _generateRoutes {
my $ctx = $c->ksb->context();
my $opt = $c->param('option') or do {
$c->res->code(400);
return $c->render;
return $c->render(text => "Invalid request sent", status => 400);
};
if (defined $ctx->{options}->{$opt}) {
$c->render(json => { $opt => $ctx->{options}->{$opt} });
}
else {
$c->res->code(404);
$c->reply->not_found;
}
});
$r->get('/modules' => sub {
my $c = shift;
$c->render(json => $c->ksb->context()->moduleList());
$c->render(json => $c->ksb->modules());
} => 'module_lookup');
$r->get('/known_modules' => sub {
......@@ -144,13 +155,22 @@ sub _generateRoutes {
my $c = shift;
my $selectorList = $c->req->json;
my $build_all = $c->req->headers->header('X-BuildAllModules');
my $log = $c->app->log;
# Remove empty selectors
my @selectors = grep { !!$_ } map { trim($_ // '') } @{$selectorList};
$log->warn("We're already in a build") if $c->in_build;
if ($build_all) {
$log->info("User requested to build all modules");
} else {
my $exactList = $c->req->text;
$log->info("User requested to build $exactList: [" . join(', ', @selectors) . "]");
}
# If not building all then ensure there's at least one module to build
if ($c->in_build || !$selectorList || (!@selectors && !$build_all) || (@selectors && $build_all)) {
$c->app->log->error("Something was wrong with modules to assign to build");
$log->error("Something was wrong with modules to assign to build");
return $c->render(text => "Invalid request sent", status => 400);
}
......
......@@ -7,7 +7,7 @@
<button id="btnSubmitModuleList">Enter modules to build:</button>
<div class="module_list_div">
<label for="module_select">Or use the dropdown to select</label>
<label for="module_select">Or <strike>use the dropdown to select</strike></label>
<select multiple id="module_select" size="15">
<option value="">All</option>
<option value="###">--- Module names loading ---</option>
......@@ -33,7 +33,17 @@ btnSubmitModuleList.addEventListener('click', (ev) => {
'Content-Type': 'application/json'
}
})
.then(resp => resp.json())
.then(resp => {
if(resp.ok) {
return resp.json()
}
else {
return resp.text().then(err => {
lkup('modules_result_div').innerHTML = "<b>ERROR</b>: " + err;
throw ("Posting selectors to kdesrc-build backend led to error: " + err);
});
}
})
.then(resp => {
console.log(`Response received ${resp}`);
lkup('btnStartBuild').disabled = false;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment