Skip to content

Commit

Permalink
Throw on warnings by default; Add onWarning loader option
Browse files Browse the repository at this point in the history
Related to issue #121
  • Loading branch information
dervus committed Jun 17, 2014
1 parent d6fd090 commit e6bac15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ options:

- `filename` _(default: null)_ - string to be used as a file path in
error/warning messages.
- `strict` _(default - false)_ makes the loader to throw errors instead of
warnings.
- `onWarning` _(default: null)_ - function to call on warning messages.
Loader will throw on warnings if this function is not provided.
- `schema` _(default: `DEFAULT_SAFE_SCHEMA`)_ - specifies a schema to use.
- `FAILSAFE_SCHEMA` - only strings, arrays and plain objects:
http://www.yaml.org/spec/1.2/spec.html#id2802346
Expand Down
20 changes: 10 additions & 10 deletions lib/js-yaml/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ function simpleEscapeSequence(c) {


function State(input, options) {
this.input = input;
this.input = input;

this.filename = options['filename'] || null;
this.schema = options['schema'] || DEFAULT_FULL_SCHEMA;
this.strict = options['strict'] || false;
this.legacy = options['legacy'] || false;
this.filename = options['filename'] || null;
this.schema = options['schema'] || DEFAULT_FULL_SCHEMA;
this.onWarning = options['onWarning'] || null;
this.legacy = options['legacy'] || false;

this.implicitTypes = this.schema.compiledImplicit;
this.typeMap = this.schema.compiledTypeMap;
this.implicitTypes = this.schema.compiledImplicit;
this.typeMap = this.schema.compiledTypeMap;

this.length = input.length;
this.position = 0;
Expand Down Expand Up @@ -145,10 +145,10 @@ function throwError(state, message) {
function throwWarning(state, message) {
var error = generateError(state, message);

if (state.strict) {
throw error;
if (state.onWarning) {
state.onWarning.call(null, error);
} else {
console.warn(error.toString());
throw error;
}
}

Expand Down

0 comments on commit e6bac15

Please sign in to comment.