ui: better training validation output

This commit is contained in:
undefined committed 2022-08-09 20:35:44 +08:00
1 parent 9a44422522
commit 6bda0e58d3
9 files changed
+13 -6

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "3.15.7", "version": "3.15.8",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "src/loader", "main": "src/loader",
"module": "src/loader", "module": "src/loader",
+1 -1
View File
@@ -107,7 +107,7 @@ export const ProblemDataNotFoundError = Err('ProblemDataNotFoundError', NotFound
export const MessageNotFoundError = Err('MessageNotFoundError', NotFoundError, 'Message {0} not found.'); export const MessageNotFoundError = Err('MessageNotFoundError', NotFoundError, 'Message {0} not found.');
export const DocumentNotFoundError = Err('DocumentNotFoundError', NotFoundError, 'Document {2} not found.'); export const DocumentNotFoundError = Err('DocumentNotFoundError', NotFoundError, 'Document {2} not found.');
export const ProblemNotFoundError = Err('ProblemNotFountError', DocumentNotFoundError, 'Problem {1} not found.'); export const ProblemNotFoundError = Err('ProblemNotFoundError', DocumentNotFoundError, 'Problem {1} not found.');
export const SolutionNotFoundError = Err('SolutionNotFoundError', DocumentNotFoundError, 'Solution {1} not found.'); export const SolutionNotFoundError = Err('SolutionNotFoundError', DocumentNotFoundError, 'Solution {1} not found.');
export const TrainingNotFoundError = Err('TrainingNotFoundError', DocumentNotFoundError, 'Training {1} not found.'); export const TrainingNotFoundError = Err('TrainingNotFoundError', DocumentNotFoundError, 'Training {1} not found.');
export const ContestNotFoundError = Err('ContestNotFoundError', DocumentNotFoundError, 'Contest {1} not found.'); export const ContestNotFoundError = Err('ContestNotFoundError', DocumentNotFoundError, 'Contest {1} not found.');
+1 -1
View File
@@ -49,7 +49,7 @@ async function _parseDagJson(domainId: string, _dag: string): Promise<Tdoc['dag'
parsed.push(newNode); parsed.push(newNode);
} }
} catch (e) { } catch (e) {
throw new ValidationError('dag', null, e.message); throw new ValidationError('dag', null, e instanceof ProblemNotFoundError ? e : e.message);
} }
return parsed; return parsed;
} }
+1
View File
@@ -202,6 +202,7 @@ export class ProblemModel {
static async copy(domainId: string, _id: number, target: string, pid?: string) { static async copy(domainId: string, _id: number, target: string, pid?: string) {
const original = await ProblemModel.get(domainId, _id); const original = await ProblemModel.get(domainId, _id);
if (!original) throw new ProblemNotFoundError(domainId, _id); if (!original) throw new ProblemNotFoundError(domainId, _id);
// TODO: refuse to copy referenced problem
if (pid && (/^[0-9]+$/.test(pid) || await ProblemModel.get(target, pid))) pid = ''; if (pid && (/^[0-9]+$/.test(pid) || await ProblemModel.get(target, pid))) pid = '';
if (!pid && original.pid && !await ProblemModel.get(target, original.pid)) pid = original.pid; if (!pid && original.pid && !await ProblemModel.get(target, original.pid)) pid = original.pid;
const docId = await ProblemModel.add( const docId = await ProblemModel.add(
@@ -51,7 +51,7 @@ export default (logger) => async (ctx: KoaContext, next) => {
if (request.json) response.body = { error }; if (request.json) response.body = { error };
else { else {
try { try {
await ctx.render(error instanceof UserFacingError ? 'error.html' : 'bsod.html', { error }); await ctx.render(error instanceof UserFacingError ? 'error.html' : 'bsod.html', { UserFacingError, error });
} catch (e) { } catch (e) {
logger.error(e); logger.error(e);
// this.response.body.error = {}; // this.response.body.error = {};
+1
View File
@@ -246,6 +246,7 @@ export class Handler extends HandlerCommon {
this.response.status = error instanceof UserFacingError ? error.code : 500; this.response.status = error instanceof UserFacingError ? error.code : 500;
this.response.template = error instanceof UserFacingError ? 'error.html' : 'bsod.html'; this.response.template = error instanceof UserFacingError ? 'error.html' : 'bsod.html';
this.response.body = { this.response.body = {
UserFacingError,
error: { message: error.msg(), params: error.params, stack: errorMessage(error.stack || '') }, error: { message: error.msg(), params: error.params, stack: errorMessage(error.stack || '') },
}; };
} }
@@ -146,6 +146,7 @@ env.addGlobal('Math', Math);
env.addGlobal('process', process); env.addGlobal('process', process);
env.addGlobal('global', global); env.addGlobal('global', global);
env.addGlobal('typeof', (o) => typeof o); env.addGlobal('typeof', (o) => typeof o);
env.addGlobal('instanceof', (a, b) => a instanceof b);
env.addGlobal('paginate', misc.paginate); env.addGlobal('paginate', misc.paginate);
env.addGlobal('size', misc.size); env.addGlobal('size', misc.size);
env.addGlobal('utils', { status }); env.addGlobal('utils', { status });
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/ui-default", "name": "@hydrooj/ui-default",
"version": "4.39.2", "version": "4.39.3",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "hydro.js", "main": "hydro.js",
+5 -1
View File
@@ -12,7 +12,11 @@
<p>{{ _('Arguments') }}: <p>{{ _('Arguments') }}:
<ol> <ol>
{%- for param in error.params -%} {%- for param in error.params -%}
<li>{{ param }}</li> {% if instanceof(param, UserFacingError) %}
<li>{{ _(param.message).formatFromArray(param.params)}}</li>
{% else %}
<li>{{ param }}</li>
{% endif %}
{%- endfor -%} {%- endfor -%}
</ol> </ol>
</p> </p>