Skip to content

Commit

Permalink
Rename GenericError to JSONParserError
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Mar 16, 2020
1 parent 9c57f22 commit fdb2774
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
16 changes: 8 additions & 8 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ declare class $RefParser {
*
* See https://github.com/APIDevTools/json-schema-ref-parser/blob/master/docs/ref-parser.md#errors
*/
errors: Array<$RefParser.GenericError | $RefParser.InvalidPointerError | $RefParser.ResolverError | $RefParser.ParserError | $RefParser.MissingPointerError | $RefParser.UnmatchedParserError | $RefParser.UnmatchedResolverError>;
errors: Array<$RefParser.JSONParserError | $RefParser.InvalidPointerError | $RefParser.ResolverError | $RefParser.ParserError | $RefParser.MissingPointerError | $RefParser.UnmatchedParserError | $RefParser.UnmatchedResolverError>;

/**
* Dereferences all `$ref` pointers in the JSON Schema, replacing each reference with its resolved value. This results in a schema object that does not contain any `$ref` pointers. Instead, it's a normal JavaScript object tree that can easily be crawled and used just like any other JavaScript object. This is great for programmatic usage, especially when using tools that don't understand JSON references.
Expand Down Expand Up @@ -411,18 +411,18 @@ declare namespace $RefParser {
set($ref: string, value: JSONSchema4Type | JSONSchema6Type): void
}

export class GenericError extends Error {
export class JSONParserError extends Error {
readonly message: string;
readonly path: Array<string | number>;
readonly source: string;
}

export class ParserError extends GenericError {}
export class UnmatchedParserError extends GenericError {}
export class ResolverError extends GenericError {
export class ParserError extends JSONParserError {}
export class UnmatchedParserError extends JSONParserError {}
export class ResolverError extends JSONParserError {
readonly code?: string;
}
export class UnmatchedResolverError extends GenericError {}
export class MissingPointerError extends GenericError {}
export class InvalidPointerError extends GenericError {}
export class UnmatchedResolverError extends JSONParserError {}
export class MissingPointerError extends JSONParserError {}
export class InvalidPointerError extends JSONParserError {}
}
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const resolveExternal = require("./resolve-external");
const bundle = require("./bundle");
const dereference = require("./dereference");
const url = require("./util/url");
const { GenericError, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError } = require("./util/errors");
const { JSONParserError, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError } = require("./util/errors");
const maybe = require("call-me-maybe");
const { ono } = require("@jsdevtools/ono");

module.exports = $RefParser;
module.exports.YAML = require("./util/yaml");
module.exports.GenericError = GenericError;
module.exports.JSONParserError = JSONParserError;
module.exports.InvalidPointerError = InvalidPointerError;
module.exports.MissingPointerError = MissingPointerError;
module.exports.ResolverError = ResolverError;
Expand Down Expand Up @@ -48,7 +48,7 @@ function $RefParser () {

/**
* List of all errors
* @type {Array<GenericError | ResolverError | ParserError | MissingPointerError | UnmatchedResolverError | UnmatchedResolverError>}
* @type {Array<JSONParserError | ResolverError | ParserError | MissingPointerError | UnmatchedResolverError | UnmatchedResolverError>}
*/
Object.defineProperty($RefParser.prototype, "errors", {
get () {
Expand Down
4 changes: 2 additions & 2 deletions lib/pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = Pointer;

const $Ref = require("./ref");
const url = require("./util/url");
const { GenericError, InvalidPointerError, MissingPointerError, isHandledError } = require("./util/errors");
const { JSONParserError, InvalidPointerError, MissingPointerError, isHandledError } = require("./util/errors");
const slashes = /\//g;
const tildes = /~/g;
const escapedSlash = /~1/g;
Expand Down Expand Up @@ -268,7 +268,7 @@ function setValue (pointer, token, value) {
}
}
else {
throw new GenericError(`Error assigning $ref pointer "${pointer.path}". \nCannot set "${token}" of a non-object.`);
throw new JSONParserError(`Error assigning $ref pointer "${pointer.path}". \nCannot set "${token}" of a non-object.`);
}
return value;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module.exports = $Ref;

const Pointer = require("./pointer");
const { GenericError, GenericErrorGroup, ParserError, MissingPointerError, ResolverError, isHandledError } = require("./util/errors");
const { JSONParserError, JSONParserErrorGroup, ParserError, MissingPointerError, ResolverError, isHandledError } = require("./util/errors");
const { safePointerToPath } = require("./util/url");

/**
Expand Down Expand Up @@ -45,15 +45,15 @@ function $Ref () {

/**
* List of all errors. Undefined if no errors.
* @type {Array<GenericError | ResolverError | ParserError | MissingPointerError>}
* @type {Array<JSONParserError | ResolverError | ParserError | MissingPointerError>}
*/
this.errors = undefined;
}

/**
* Pushes an error to errors array.
*
* @param {Array<GenericError | GenericErrorGroup>} error - The error to be pushed
* @param {Array<JSONParserError | JSONParserErrorGroup>} error - The error to be pushed
* @returns {void}
*/
$Ref.prototype.addError = function (err) {
Expand Down
22 changes: 11 additions & 11 deletions lib/util/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { Ono } = require("@jsdevtools/ono");

const { stripHash } = require("./url");

const GenericError = exports.GenericError = class GenericError extends Error {
const JSONParserError = exports.JSONParserError = class JSONParserError extends Error {
constructor (message, source) {
super();

Expand All @@ -16,9 +16,9 @@ const GenericError = exports.GenericError = class GenericError extends Error {
}
};

setErrorName(GenericError);
setErrorName(JSONParserError);

const GenericErrorGroup = exports.GenericErrorGroup = class GenericErrorGroup extends Error {
const JSONParserErrorGroup = exports.JSONParserErrorGroup = class JSONParserErrorGroup extends Error {
constructor (errors, source) {
super();

Expand Down Expand Up @@ -54,7 +54,7 @@ const GenericErrorGroup = exports.GenericErrorGroup = class GenericErrorGroup ex
}
};

exports.StoplightParserError = class StoplightParserError extends GenericErrorGroup {
exports.StoplightParserError = class StoplightParserError extends JSONParserErrorGroup {
constructor (diagnostics, source) {
super(diagnostics.filter(StoplightParserError.pickError).map(error => {
let parserError = new ParserError(error.message, source);
Expand All @@ -74,23 +74,23 @@ exports.StoplightParserError = class StoplightParserError extends GenericErrorGr
}
};

const ParserError = exports.ParserError = class ParserError extends GenericError {
const ParserError = exports.ParserError = class ParserError extends JSONParserError {
constructor (message, source) {
super(`Error parsing ${source}: ${message}`, source);
}
};

setErrorName(ParserError);

const UnmatchedParserError = exports.UnmatchedParserError = class UnmatchedParserError extends GenericError {
const UnmatchedParserError = exports.UnmatchedParserError = class UnmatchedParserError extends JSONParserError {
constructor (source) {
super(`Could not find parser for "${source}"`, source);
}
};

setErrorName(UnmatchedParserError);

const ResolverError = exports.ResolverError = class ResolverError extends GenericError {
const ResolverError = exports.ResolverError = class ResolverError extends JSONParserError {
constructor (ex, source) {
super(ex.message || `Error reading file "${source}"`, source);
if ("code" in ex) {
Expand All @@ -101,23 +101,23 @@ const ResolverError = exports.ResolverError = class ResolverError extends Generi

setErrorName(ResolverError);

const UnmatchedResolverError = exports.UnmatchedResolverError = class UnmatchedResolverError extends GenericError {
const UnmatchedResolverError = exports.UnmatchedResolverError = class UnmatchedResolverError extends JSONParserError {
constructor (source) {
super(`Could not find resolver for "${source}"`, source);
}
};

setErrorName(UnmatchedResolverError);

const MissingPointerError = exports.MissingPointerError = class MissingPointerError extends GenericError {
const MissingPointerError = exports.MissingPointerError = class MissingPointerError extends JSONParserError {
constructor (token, path) {
super(`Token "${token}" does not exist.`, stripHash(path));
}
};

setErrorName(MissingPointerError);

const InvalidPointerError = exports.InvalidPointerError = class InvalidPointerError extends GenericError {
const InvalidPointerError = exports.InvalidPointerError = class InvalidPointerError extends JSONParserError {
constructor (pointer, path) {
super(`Invalid $ref pointer "${pointer}". Pointers must begin with "#/"`, stripHash(path));
}
Expand All @@ -133,5 +133,5 @@ function setErrorName (err) {
}

exports.isHandledError = function (err) {
return err instanceof GenericError || err instanceof GenericErrorGroup;
return err instanceof JSONParserError || err instanceof JSONParserErrorGroup;
};

0 comments on commit fdb2774

Please sign in to comment.