@little-nebulae/error 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +21 -0
- package/README.md +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +29 -0
- package/package.json +43 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ryan Luong
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Error lib
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type BaseErrorMeta = Record<string, unknown> | null;
|
|
3
|
+
interface BaseErrorType<TCode extends string, TCause = unknown, TMeta extends BaseErrorMeta = null> extends Error {
|
|
4
|
+
cause: TCause;
|
|
5
|
+
code: TCode;
|
|
6
|
+
meta: TMeta;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/classes/base.d.ts
|
|
10
|
+
export declare abstract class BaseError<TCode extends string, TCause = unknown, TMeta extends BaseErrorMeta = null> extends Error implements BaseErrorType<TCode, TCause, TMeta> {
|
|
11
|
+
abstract readonly name: string;
|
|
12
|
+
cause: TCause;
|
|
13
|
+
abstract readonly code: TCode;
|
|
14
|
+
readonly meta: TMeta;
|
|
15
|
+
constructor({ message, cause, meta }: {
|
|
16
|
+
message: string;
|
|
17
|
+
cause: TCause;
|
|
18
|
+
meta: TMeta;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/classes/unexpected.d.ts
|
|
23
|
+
export declare const UNEXPECTED_ERROR_CODE = "UNEXPECTED_ERROR";
|
|
24
|
+
export type UnexpectedErrorCode = typeof UNEXPECTED_ERROR_CODE;
|
|
25
|
+
export declare class UnexpectedError<TCause = unknown, TMeta extends BaseErrorMeta = null> extends BaseError<UnexpectedErrorCode, TCause, TMeta> {
|
|
26
|
+
readonly name = "UnexpectedError";
|
|
27
|
+
readonly code = "UNEXPECTED_ERROR";
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/helpers/compose-error-message.d.ts
|
|
31
|
+
export declare function composeErrorMessage<TOperation extends string, TReason extends string>({ operation, reason }: {
|
|
32
|
+
operation: TOperation;
|
|
33
|
+
reason: TReason;
|
|
34
|
+
}): `Failed to ${TOperation} due to ${TReason}.`;
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/helpers/is-error.d.ts
|
|
37
|
+
export declare function isError(value: unknown): value is Error;
|
|
38
|
+
//#endregion
|
|
39
|
+
export type { BaseErrorMeta, BaseErrorType };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/classes/base.ts
|
|
2
|
+
var BaseError = class extends Error {
|
|
3
|
+
meta;
|
|
4
|
+
constructor({ message, cause, meta }) {
|
|
5
|
+
super(message, { cause });
|
|
6
|
+
this.meta = meta;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/classes/unexpected.ts
|
|
11
|
+
const UNEXPECTED_ERROR_CODE = "UNEXPECTED_ERROR";
|
|
12
|
+
var UnexpectedError = class extends BaseError {
|
|
13
|
+
name = "UnexpectedError";
|
|
14
|
+
code = UNEXPECTED_ERROR_CODE;
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/helpers/compose-error-message.ts
|
|
18
|
+
function composeErrorMessage({ operation, reason }) {
|
|
19
|
+
return `Failed to ${operation} due to ${reason}.`;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/helpers/is-error.ts
|
|
23
|
+
function isError(value) {
|
|
24
|
+
if (Object.hasOwn(Error, "isError") && Error.isError(value)) return true;
|
|
25
|
+
if (value instanceof Error) return true;
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { BaseError, UNEXPECTED_ERROR_CODE, UnexpectedError, composeErrorMessage, isError };
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@little-nebulae/error",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/index.js",
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@arethetypeswrong/core": "0.18.5",
|
|
15
|
+
"@types/node": "26.4.1",
|
|
16
|
+
"oxfmt": "0.67.0",
|
|
17
|
+
"oxlint": "1.82.0",
|
|
18
|
+
"oxlint-tsgolint": "7.0.2001",
|
|
19
|
+
"publint": "0.3.24",
|
|
20
|
+
"tsdown": "0.23.0",
|
|
21
|
+
"tsx": "4.23.13",
|
|
22
|
+
"typescript": "7.0.2",
|
|
23
|
+
"vitest": "5.0.0"
|
|
24
|
+
},
|
|
25
|
+
"devEngines": {
|
|
26
|
+
"packageManager": {
|
|
27
|
+
"name": "pnpm",
|
|
28
|
+
"version": "12.4.1",
|
|
29
|
+
"onFail": "warn"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsdown",
|
|
34
|
+
"try": "tsx src/try.ts",
|
|
35
|
+
"fmt": "oxfmt --disable-nested-config",
|
|
36
|
+
"fmt:check": "oxfmt --check --disable-nested-config",
|
|
37
|
+
"lint": "oxlint --disable-nested-config",
|
|
38
|
+
"lint:fix": "oxlint --fix --disable-nested-config",
|
|
39
|
+
"check": "pnpm run lint && pnpm run fmt:check",
|
|
40
|
+
"fix": "pnpm run lint:fix && pnpm run fmt",
|
|
41
|
+
"test": "vitest run"
|
|
42
|
+
}
|
|
43
|
+
}
|