Skip to content

Commit

Permalink
fix: improved error message
Browse files Browse the repository at this point in the history
  • Loading branch information
bbtgnn committed Mar 1, 2024
1 parent df617a9 commit 3b88799
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/_modules/dao/base_document_handling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import _ from 'lodash';

import { Type as T, type Static, type TAnySchema, type StaticDecode } from '@sinclair/typebox';
import { Value } from '@sinclair/typebox/value';
import { Value, type ValueError } from '@sinclair/typebox/value';

import document_module_record from '$database/_export';

Expand Down Expand Up @@ -118,16 +118,23 @@ export function parse_base_document<T extends TAnySchema>(
const errors = [...Value.Errors(schema, base_document)];
return new Error(`
Parse error:
Processing error:
${base_document._path}
Provided value:
${JSON.stringify(base_document, null, 2)}
Errors:
${JSON.stringify(errors, null, 2)}
${JSON.stringify(format_errors(errors), null, 2)}
`);
}
});
}

function format_errors(errors: ValueError[]) {
return errors.map((e) => ({
message: e.message,
path: e.path
}));
}

0 comments on commit 3b88799

Please sign in to comment.