Skip to content

Commit

Permalink
[FIX] Fix error handling and reporting of stereotype.
Browse files Browse the repository at this point in the history
  • Loading branch information
shellyln committed Mar 1, 2020
1 parent 30d55f2 commit a0f5e57
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.3.1

* `[FIX]` Fix error handling and reporting of stereotype.
* Improve playground.


## v0.3.0

* Add `@stereotype` decorator.
Expand Down
24 changes: 23 additions & 1 deletion docs/playground/assets/script/playground2.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ interface EntryBase {
name: string;
/** ACL infos */
acl: ACL[];
/** Timestamp */
@stereotype('datetime')
timestamp: string;
}
/** File entry */
Expand Down Expand Up @@ -239,6 +242,7 @@ class App extends React.Component {
const ctx = {
checkAll: true,
schema,
stereotypes: new Map(tynder.stereotypes),
};
if (tynder.validate(JSON.parse(data), tynder.getType(schema, targetEntryName.value), ctx)) {
r = `Validation succeeded. (Tynder)`;
Expand Down Expand Up @@ -306,8 +310,26 @@ class App extends React.Component {
targetEntryName.value = 'Folder';
}
{
const now = new Date();
const editor = AppState.AceEditor['dataEditor'];
editor.setValue(`{}`);
editor.setValue(JSON.stringify({
type: 'folder',
name: 'foo',
entries: [{
type: 'file',
name: 'bar',
acl: [{
target: 'a',
value: 'deny',
}],
timestamp: now.toISOString(),
}],
acl: [{
target: 'a',
value: 'deny',
}],
timestamp: now.toISOString(),
}, null, 2));
editor.clearSelection();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ export function formatErrorMessage(

const dict = new Map<string, string>([
['expectedType',
ty.stereotype ?
ty.stereotype :
escapeString(getExpectedType(ty))],
['type',
escapeString(typeof data)],
Expand Down
1 change: 1 addition & 0 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ function validatePrimitiveTypeAssertion<T>(

let chkSt = checkStereotypes(chkTarget, ty, ctx);
if (chkSt === null) {
reportError(ErrorTypes.TypeUnmatched, data, ty, {ctx});
return null;
} else if (chkSt === false) {
chkSt = {
Expand Down

0 comments on commit a0f5e57

Please sign in to comment.