-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow throwing error on invalid parsing input (#312)
* feat: allow throwing error on invalid parsing input * feat: rename option throwOnError to throwOnFailure
- Loading branch information
Showing
54 changed files
with
976 additions
and
269 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (c) 2023. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import { BaseError as Base } from 'ebec'; | ||
import { ErrorCode } from './code'; | ||
|
||
export class BaseError extends Base { | ||
get code() : `${ErrorCode}` { | ||
return this.getOption('code') as `${ErrorCode}` || ErrorCode.NONE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) 2023. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import type { Options } from 'ebec'; | ||
import { isObject } from '../utils'; | ||
import { BaseError } from './base'; | ||
|
||
export class BuildError extends BaseError { | ||
constructor(message?: string | Options) { | ||
if (isObject(message)) { | ||
message.message = 'A building error has occurred.'; | ||
} | ||
|
||
super(message || 'A building error has occurred.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) 2023. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
export enum ErrorCode { | ||
NONE = 'none', | ||
|
||
INPUT_INVALID = 'inputInvalid', | ||
|
||
KEY_INVALID = 'keyInvalid', | ||
|
||
KEY_PATH_INVALID = 'keyPathInvalid', | ||
|
||
KEY_NOT_ALLOWED = 'keyNotAllowed', | ||
|
||
KEY_VALUE_INVALID = 'keyValueInvalid', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright (c) 2023. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
export * from './base'; | ||
export * from './build'; | ||
export * from './code'; | ||
export * from './parse'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2023. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import type { Options } from 'ebec'; | ||
import { isObject } from '../utils'; | ||
import { BaseError } from './base'; | ||
import { ErrorCode } from './code'; | ||
|
||
export class ParseError extends BaseError { | ||
constructor(message?: string | Options) { | ||
if (isObject(message)) { | ||
message.message = message.message || 'A parsing error has occurred.'; | ||
} | ||
|
||
super(message || 'A parsing error has occurred.'); | ||
} | ||
|
||
static inputInvalid() { | ||
return new this({ | ||
message: 'The shape of the input is not valid.', | ||
code: ErrorCode.INPUT_INVALID, | ||
}); | ||
} | ||
|
||
static keyNotAllowed(name: string) { | ||
return new this({ | ||
message: `The key ${name} is not covered by allowed/default options.`, | ||
code: ErrorCode.KEY_NOT_ALLOWED, | ||
}); | ||
} | ||
|
||
static keyInvalid(key: string) { | ||
return new this({ | ||
message: `The key ${key} is invalid.`, | ||
code: ErrorCode.KEY_INVALID, | ||
}); | ||
} | ||
|
||
static keyPathInvalid(key: string) { | ||
return new this({ | ||
message: `The key path ${key} is invalid.`, | ||
code: ErrorCode.KEY_PATH_INVALID, | ||
}); | ||
} | ||
|
||
static keyValueInvalid(key: string) { | ||
return new this({ | ||
message: `The value of the key ${key} is invalid.`, | ||
code: ErrorCode.KEY_VALUE_INVALID, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright (c) 2023. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import { BuildError } from '../../../errors'; | ||
|
||
export class FieldsBuildError extends BuildError { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright (c) 2023. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
export * from './build'; | ||
export * from './parse'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright (c) 2023. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import { ParseError } from '../../../errors'; | ||
|
||
export class FieldsParseError extends ParseError { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.