@tochii/errors 0.1.2 → 0.1.8

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/CHANGELOG.md ADDED
@@ -0,0 +1,61 @@
1
+ # Changelog
2
+
3
+ ## 0.1.8 (October 2026)
4
+
5
+ <!-- release:start -->
6
+
7
+ ### Bug fixes
8
+ #### Ci
9
+ - Resynced with `dbx sync` to avoid drift ([#1c6f358](https://github.com/tochiResources/errors/commit/1c6f358) by [T0chi](https://github.com/T0chi))
10
+
11
+ <!-- release:end -->
12
+
13
+
14
+ ## 0.1.7 (October 2026)
15
+
16
+ ### Bug fixes
17
+ #### Ci
18
+ - Change trigger for `nuget.yml` workflow to `release` ([#582ad2c](https://github.com/tochiResources/errors/commit/582ad2c) by [T0chi](https://github.com/T0chi))
19
+
20
+ ## 0.1.6 (October 2026)
21
+
22
+ ### CI
23
+ - Updated workflows ([#b1a1b89](https://github.com/tochiResources/errors/commit/b1a1b89) by [T0chi](https://github.com/T0chi))
24
+
25
+ ## 0.1.5 (October 2026)
26
+
27
+ ### CI
28
+ - Added `dev` to `ci.yml`'s push branches ([#ff15308](https://github.com/tochiResources/errors/commit/ff15308) by [T0chi](https://github.com/T0chi))
29
+
30
+ ## 0.1.4 (October 2026)
31
+
32
+ ### CI
33
+ - Updated workflows ([#b2e3380](https://github.com/tochiResources/errors/commit/b2e3380) by [T0chi](https://github.com/T0chi))
34
+
35
+ ## 0.1.3 (October 2026)
36
+
37
+ ### Chores
38
+ - Set package to public ([#a8428d3](https://github.com/tochiResources/errors/commit/a8428d3) by [T0chi](https://github.com/T0chi))
39
+
40
+ ## 0.1.2 (October 2026)
41
+
42
+ ### CI
43
+ - Updated added `dev` branch ([#4b928a6](https://github.com/tochiResources/errors/commit/4b928a6) by [T0chi](https://github.com/T0chi))
44
+ - Updated changelog branch ([#59a6f69](https://github.com/tochiResources/errors/commit/59a6f69) by [T0chi](https://github.com/T0chi))
45
+ - Updated packaging flow ([#b4f3dbb](https://github.com/tochiResources/errors/commit/b4f3dbb) by [T0chi](https://github.com/T0chi))
46
+ ### Chores
47
+ - Added `CHANGELOG.md` ([#1b53d03](https://github.com/tochiResources/errors/commit/1b53d03) by [T0chi](https://github.com/T0chi))
48
+ - Code cleanup ([#e914f15](https://github.com/tochiResources/errors/commit/e914f15) by [T0chi](https://github.com/T0chi))
49
+ - Update package.json description ([#edf61d0](https://github.com/tochiResources/errors/commit/edf61d0) by [T0chi](https://github.com/T0chi))
50
+ #### Errors
51
+ - Initialize repository ([#e39bad5](https://github.com/tochiResources/errors/commit/e39bad5) by [T0chi](https://github.com/T0chi))
52
+
53
+ ## 0.1.1 (October 2026)
54
+
55
+ ### CI
56
+ - Updated packaging flow ([#b4f3dbb](https://github.com/tochiResources/errors/commit/b4f3dbb) by T0chi)
57
+ ### Chores
58
+ - Code cleanup ([#e914f15](https://github.com/tochiResources/errors/commit/e914f15) by T0chi)
59
+ - Update package.json description ([#edf61d0](https://github.com/tochiResources/errors/commit/edf61d0) by T0chi)
60
+ #### Errors
61
+ - Initialize repository ([#e39bad5](https://github.com/tochiResources/errors/commit/e39bad5) by T0chi)
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # @tochii/errors
2
2
 
3
+ [![tests](https://img.shields.io/github/actions/workflow/status/tochiResources/errors/ci.yml?label=tests&logo=github)](https://github.com/tochiResources/errors/actions/workflows/ci.yml)
4
+ [![npm version](https://img.shields.io/npm/v/@tochii/errors.svg?color=cb3837&label=npm)](https://www.npmjs.com/package/@tochii/errors)
5
+
3
6
  Shared typed errors and stable error codes used in official tochiResources proejcts.
4
7
 
5
8
  - **Stable codes**: the string value is part of the contract; never reuse or rename one. Both TS and C# switch on it.
package/csharp/Errors.cs CHANGED
@@ -1,275 +1,275 @@
1
- using System;
2
- using System.Collections.Generic;
3
-
4
- namespace TochiRes.Errors;
5
-
6
- /// <summary>
7
- /// Stable error codes shared with the TypeScript side (<c>@tochii/errors</c>).
8
- /// Keep in sync with <c>src/codes.ts</c>. A code is part of the
9
- /// public contract: never rename or reuse one — add a new code instead.
10
- /// </summary>
11
- public static class ErrorCodes
12
- {
13
- // General
14
- public const string Unknown = "TOCHIRES_UNKNOWN";
15
- public const string Internal = "TOCHIRES_INTERNAL";
16
-
17
- // Config
18
- public const string ConfigInvalid = "TOCHIRES_CONFIG_INVALID";
19
- public const string ConfigMissing = "TOCHIRES_CONFIG_MISSING";
20
-
21
- // Validation
22
- public const string ValidationFailed = "TOCHIRES_VALIDATION_FAILED";
23
-
24
- // API / HTTP boundary
25
- public const string ApiBadRequest = "TOCHIRES_API_BAD_REQUEST";
26
- public const string ApiUnauthorized = "TOCHIRES_API_UNAUTHORIZED";
27
- public const string ApiForbidden = "TOCHIRES_API_FORBIDDEN";
28
- public const string ApiNotFound = "TOCHIRES_API_NOT_FOUND";
29
- public const string ApiConflict = "TOCHIRES_API_CONFLICT";
30
- public const string ApiUnprocessable = "TOCHIRES_API_UNPROCESSABLE";
31
- public const string ApiTooManyRequests = "TOCHIRES_API_TOO_MANY_REQUESTS";
32
- public const string ApiTimeout = "TOCHIRES_API_TIMEOUT";
33
- public const string ApiUnavailable = "TOCHIRES_API_UNAVAILABLE";
34
-
35
- // IPC
36
- public const string IpcTransport = "TOCHIRES_IPC_TRANSPORT";
37
- public const string IpcProtocol = "TOCHIRES_IPC_PROTOCOL";
38
- public const string IpcTimeout = "TOCHIRES_IPC_TIMEOUT";
39
- public const string IpcAuth = "TOCHIRES_IPC_AUTH";
40
- public const string IpcDisconnected = "TOCHIRES_IPC_DISCONNECTED";
41
- public const string IpcBackpressure = "TOCHIRES_IPC_BACKPRESSURE";
42
-
43
- // Codegen
44
- public const string CodegenUnsupported = "TOCHIRES_CODEGEN_UNSUPPORTED";
45
- public const string CodegenEmit = "TOCHIRES_CODEGEN_EMIT";
46
- public const string CodegenRoundtrip = "TOCHIRES_CODEGEN_ROUNDTRIP";
47
-
48
- // CSS
49
- public const string CssParse = "TOCHIRES_CSS_PARSE";
50
- public const string CssUnsupportedProperty = "TOCHIRES_CSS_UNSUPPORTED_PROPERTY";
51
- public const string CssUnsupportedSelector = "TOCHIRES_CSS_UNSUPPORTED_SELECTOR";
52
-
53
- // Native
54
- public const string NativeModuleNotFound = "TOCHIRES_NATIVE_MODULE_NOT_FOUND";
55
- public const string NativeMethodNotFound = "TOCHIRES_NATIVE_METHOD_NOT_FOUND";
56
- public const string NativeCallFailed = "TOCHIRES_NATIVE_CALL_FAILED";
57
-
58
- // Build
59
- public const string BuildFailed = "TOCHIRES_BUILD_FAILED";
60
- public const string BuildToolMissing = "TOCHIRES_BUILD_TOOL_MISSING";
61
-
62
- // Package
63
- public const string PackageFailed = "TOCHIRES_PACKAGE_FAILED";
64
- public const string PackageSigning = "TOCHIRES_PACKAGE_SIGNING";
65
-
66
- // Settings
67
- public const string SettingsParse = "TOCHIRES_SETTINGS_PARSE";
68
- public const string SettingsInvalid = "TOCHIRES_SETTINGS_INVALID";
69
-
70
- // Path
71
- public const string PathInvalid = "TOCHIRES_PATH_INVALID";
72
- public const string PathAbsolute = "TOCHIRES_PATH_ABSOLUTE";
73
-
74
- /// <summary>Every known code, for validation and diagnostics.</summary>
75
- public static readonly IReadOnlyList<string> All = new[]
76
- {
77
- Unknown, Internal,
78
- ConfigInvalid, ConfigMissing,
79
- ValidationFailed,
80
- ApiBadRequest, ApiUnauthorized, ApiForbidden, ApiNotFound, ApiConflict,
81
- ApiUnprocessable, ApiTooManyRequests, ApiTimeout, ApiUnavailable,
82
- IpcTransport, IpcProtocol, IpcTimeout, IpcAuth, IpcDisconnected, IpcBackpressure,
83
- CodegenUnsupported, CodegenEmit, CodegenRoundtrip,
84
- CssParse, CssUnsupportedProperty, CssUnsupportedSelector,
85
- NativeModuleNotFound, NativeMethodNotFound, NativeCallFailed,
86
- BuildFailed, BuildToolMissing,
87
- PackageFailed, PackageSigning,
88
- SettingsParse, SettingsInvalid,
89
- PathInvalid, PathAbsolute,
90
- };
91
-
92
- private static readonly IReadOnlyDictionary<string, string> CategoryByCode =
93
- new Dictionary<string, string>(StringComparer.Ordinal)
94
- {
95
- [Unknown] = "general",
96
- [Internal] = "general",
97
- [ConfigInvalid] = "config",
98
- [ConfigMissing] = "config",
99
- [ValidationFailed] = "validation",
100
- [ApiBadRequest] = "api",
101
- [ApiUnauthorized] = "api",
102
- [ApiForbidden] = "api",
103
- [ApiNotFound] = "api",
104
- [ApiConflict] = "api",
105
- [ApiUnprocessable] = "api",
106
- [ApiTooManyRequests] = "api",
107
- [ApiTimeout] = "api",
108
- [ApiUnavailable] = "api",
109
- [IpcTransport] = "ipc",
110
- [IpcProtocol] = "ipc",
111
- [IpcTimeout] = "ipc",
112
- [IpcAuth] = "ipc",
113
- [IpcDisconnected] = "ipc",
114
- [IpcBackpressure] = "ipc",
115
- [CodegenUnsupported] = "codegen",
116
- [CodegenEmit] = "codegen",
117
- [CodegenRoundtrip] = "codegen",
118
- [CssParse] = "css",
119
- [CssUnsupportedProperty] = "css",
120
- [CssUnsupportedSelector] = "css",
121
- [NativeModuleNotFound] = "native",
122
- [NativeMethodNotFound] = "native",
123
- [NativeCallFailed] = "native",
124
- [BuildFailed] = "build",
125
- [BuildToolMissing] = "build",
126
- [PackageFailed] = "package",
127
- [PackageSigning] = "package",
128
- [SettingsParse] = "settings",
129
- [SettingsInvalid] = "settings",
130
- [PathInvalid] = "path",
131
- [PathAbsolute] = "path",
132
- };
133
-
134
- /// <summary>Whether <paramref name="code"/> is one of the known stable codes.</summary>
135
- public static bool IsKnown(string? code) => code is not null && CategoryByCode.ContainsKey(code);
136
-
137
- /// <summary>The category a code belongs to, or <c>"general"</c> when unknown.</summary>
138
- public static string CategoryOf(string? code) =>
139
- code is not null && CategoryByCode.TryGetValue(code, out var category) ? category : "general";
140
- }
141
-
142
- /// <summary>
143
- /// Base exception for every error defined by this package.
144
- /// Mirrors <c>TochiResError</c> from the TypeScript implementation.
145
- /// </summary>
146
- public class TochiResException : Exception
147
- {
148
- /// <summary>Stable error code — part of the public contract.</summary>
149
- public string Code { get; }
150
-
151
- /// <summary>Coarse category derived from <see cref="Code"/>.</summary>
152
- public string Category { get; }
153
-
154
- /// <summary>Structured, JSON-safe context for logging and telemetry.</summary>
155
- public IReadOnlyDictionary<string, object?>? Context { get; }
156
-
157
- public TochiResException(
158
- string code,
159
- string message,
160
- Exception? innerException = null,
161
- IReadOnlyDictionary<string, object?>? context = null)
162
- : base(message, innerException)
163
- {
164
- Code = code;
165
- Category = ErrorCodes.CategoryOf(code);
166
- Context = context;
167
- }
168
- }
169
-
170
- /// <summary>Configuration is missing or failed validation.</summary>
171
- public sealed class ConfigException : TochiResException
172
- {
173
- public ConfigException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
174
- : base(ErrorCodes.ConfigInvalid, message, inner, context) { }
175
-
176
- public ConfigException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
177
- : base(code, message, inner, context) { }
178
- }
179
-
180
- /// <summary>A payload, schema or argument failed validation.</summary>
181
- public sealed class ValidationException : TochiResException
182
- {
183
- public ValidationException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
184
- : base(ErrorCodes.ValidationFailed, message, inner, context) { }
185
- }
186
-
187
- /// <summary>An API/HTTP boundary failure (bad request, auth, not found, conflict, …).</summary>
188
- public sealed class ApiException : TochiResException
189
- {
190
- public ApiException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
191
- : base(ErrorCodes.ApiBadRequest, message, inner, context) { }
192
-
193
- public ApiException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
194
- : base(code, message, inner, context) { }
195
- }
196
-
197
- /// <summary>An IPC transport, protocol, authentication or timeout failure.</summary>
198
- public sealed class IpcException : TochiResException
199
- {
200
- public IpcException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
201
- : base(ErrorCodes.IpcTransport, message, inner, context) { }
202
-
203
- public IpcException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
204
- : base(code, message, inner, context) { }
205
- }
206
-
207
- /// <summary>A TS→C# code generator failed or hit an unsupported construct.</summary>
208
- public sealed class CodegenException : TochiResException
209
- {
210
- public CodegenException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
211
- : base(ErrorCodes.CodegenEmit, message, inner, context) { }
212
-
213
- public CodegenException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
214
- : base(code, message, inner, context) { }
215
- }
216
-
217
- /// <summary>CSS input is invalid or outside the supported subset.</summary>
218
- public sealed class CssException : TochiResException
219
- {
220
- public CssException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
221
- : base(ErrorCodes.CssParse, message, inner, context) { }
222
-
223
- public CssException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
224
- : base(code, message, inner, context) { }
225
- }
226
-
227
- /// <summary>A native module or method was missing, or a native call failed.</summary>
228
- public sealed class NativeException : TochiResException
229
- {
230
- public NativeException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
231
- : base(ErrorCodes.NativeCallFailed, message, inner, context) { }
232
-
233
- public NativeException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
234
- : base(code, message, inner, context) { }
235
- }
236
-
237
- /// <summary>A build pipeline step failed or a required tool is missing.</summary>
238
- public sealed class BuildException : TochiResException
239
- {
240
- public BuildException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
241
- : base(ErrorCodes.BuildFailed, message, inner, context) { }
242
-
243
- public BuildException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
244
- : base(code, message, inner, context) { }
245
- }
246
-
247
- /// <summary>A packaging, signing or notarization step failed.</summary>
248
- public sealed class PackageException : TochiResException
249
- {
250
- public PackageException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
251
- : base(ErrorCodes.PackageFailed, message, inner, context) { }
252
-
253
- public PackageException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
254
- : base(code, message, inner, context) { }
255
- }
256
-
257
- /// <summary>Settings text could not be parsed or failed validation.</summary>
258
- public sealed class SettingsException : TochiResException
259
- {
260
- public SettingsException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
261
- : base(ErrorCodes.SettingsInvalid, message, inner, context) { }
262
-
263
- public SettingsException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
264
- : base(code, message, inner, context) { }
265
- }
266
-
267
- /// <summary>A path was malformed or violated the relative-path rule.</summary>
268
- public sealed class PathException : TochiResException
269
- {
270
- public PathException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
271
- : base(ErrorCodes.PathInvalid, message, inner, context) { }
272
-
273
- public PathException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
274
- : base(code, message, inner, context) { }
275
- }
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace TochiRes.Errors;
5
+
6
+ /// <summary>
7
+ /// Stable error codes shared with the TypeScript side (<c>@tochii/errors</c>).
8
+ /// Keep in sync with <c>src/codes.ts</c>. A code is part of the
9
+ /// public contract: never rename or reuse one — add a new code instead.
10
+ /// </summary>
11
+ public static class ErrorCodes
12
+ {
13
+ // General
14
+ public const string Unknown = "TOCHIRES_UNKNOWN";
15
+ public const string Internal = "TOCHIRES_INTERNAL";
16
+
17
+ // Config
18
+ public const string ConfigInvalid = "TOCHIRES_CONFIG_INVALID";
19
+ public const string ConfigMissing = "TOCHIRES_CONFIG_MISSING";
20
+
21
+ // Validation
22
+ public const string ValidationFailed = "TOCHIRES_VALIDATION_FAILED";
23
+
24
+ // API / HTTP boundary
25
+ public const string ApiBadRequest = "TOCHIRES_API_BAD_REQUEST";
26
+ public const string ApiUnauthorized = "TOCHIRES_API_UNAUTHORIZED";
27
+ public const string ApiForbidden = "TOCHIRES_API_FORBIDDEN";
28
+ public const string ApiNotFound = "TOCHIRES_API_NOT_FOUND";
29
+ public const string ApiConflict = "TOCHIRES_API_CONFLICT";
30
+ public const string ApiUnprocessable = "TOCHIRES_API_UNPROCESSABLE";
31
+ public const string ApiTooManyRequests = "TOCHIRES_API_TOO_MANY_REQUESTS";
32
+ public const string ApiTimeout = "TOCHIRES_API_TIMEOUT";
33
+ public const string ApiUnavailable = "TOCHIRES_API_UNAVAILABLE";
34
+
35
+ // IPC
36
+ public const string IpcTransport = "TOCHIRES_IPC_TRANSPORT";
37
+ public const string IpcProtocol = "TOCHIRES_IPC_PROTOCOL";
38
+ public const string IpcTimeout = "TOCHIRES_IPC_TIMEOUT";
39
+ public const string IpcAuth = "TOCHIRES_IPC_AUTH";
40
+ public const string IpcDisconnected = "TOCHIRES_IPC_DISCONNECTED";
41
+ public const string IpcBackpressure = "TOCHIRES_IPC_BACKPRESSURE";
42
+
43
+ // Codegen
44
+ public const string CodegenUnsupported = "TOCHIRES_CODEGEN_UNSUPPORTED";
45
+ public const string CodegenEmit = "TOCHIRES_CODEGEN_EMIT";
46
+ public const string CodegenRoundtrip = "TOCHIRES_CODEGEN_ROUNDTRIP";
47
+
48
+ // CSS
49
+ public const string CssParse = "TOCHIRES_CSS_PARSE";
50
+ public const string CssUnsupportedProperty = "TOCHIRES_CSS_UNSUPPORTED_PROPERTY";
51
+ public const string CssUnsupportedSelector = "TOCHIRES_CSS_UNSUPPORTED_SELECTOR";
52
+
53
+ // Native
54
+ public const string NativeModuleNotFound = "TOCHIRES_NATIVE_MODULE_NOT_FOUND";
55
+ public const string NativeMethodNotFound = "TOCHIRES_NATIVE_METHOD_NOT_FOUND";
56
+ public const string NativeCallFailed = "TOCHIRES_NATIVE_CALL_FAILED";
57
+
58
+ // Build
59
+ public const string BuildFailed = "TOCHIRES_BUILD_FAILED";
60
+ public const string BuildToolMissing = "TOCHIRES_BUILD_TOOL_MISSING";
61
+
62
+ // Package
63
+ public const string PackageFailed = "TOCHIRES_PACKAGE_FAILED";
64
+ public const string PackageSigning = "TOCHIRES_PACKAGE_SIGNING";
65
+
66
+ // Settings
67
+ public const string SettingsParse = "TOCHIRES_SETTINGS_PARSE";
68
+ public const string SettingsInvalid = "TOCHIRES_SETTINGS_INVALID";
69
+
70
+ // Path
71
+ public const string PathInvalid = "TOCHIRES_PATH_INVALID";
72
+ public const string PathAbsolute = "TOCHIRES_PATH_ABSOLUTE";
73
+
74
+ /// <summary>Every known code, for validation and diagnostics.</summary>
75
+ public static readonly IReadOnlyList<string> All = new[]
76
+ {
77
+ Unknown, Internal,
78
+ ConfigInvalid, ConfigMissing,
79
+ ValidationFailed,
80
+ ApiBadRequest, ApiUnauthorized, ApiForbidden, ApiNotFound, ApiConflict,
81
+ ApiUnprocessable, ApiTooManyRequests, ApiTimeout, ApiUnavailable,
82
+ IpcTransport, IpcProtocol, IpcTimeout, IpcAuth, IpcDisconnected, IpcBackpressure,
83
+ CodegenUnsupported, CodegenEmit, CodegenRoundtrip,
84
+ CssParse, CssUnsupportedProperty, CssUnsupportedSelector,
85
+ NativeModuleNotFound, NativeMethodNotFound, NativeCallFailed,
86
+ BuildFailed, BuildToolMissing,
87
+ PackageFailed, PackageSigning,
88
+ SettingsParse, SettingsInvalid,
89
+ PathInvalid, PathAbsolute,
90
+ };
91
+
92
+ private static readonly IReadOnlyDictionary<string, string> CategoryByCode =
93
+ new Dictionary<string, string>(StringComparer.Ordinal)
94
+ {
95
+ [Unknown] = "general",
96
+ [Internal] = "general",
97
+ [ConfigInvalid] = "config",
98
+ [ConfigMissing] = "config",
99
+ [ValidationFailed] = "validation",
100
+ [ApiBadRequest] = "api",
101
+ [ApiUnauthorized] = "api",
102
+ [ApiForbidden] = "api",
103
+ [ApiNotFound] = "api",
104
+ [ApiConflict] = "api",
105
+ [ApiUnprocessable] = "api",
106
+ [ApiTooManyRequests] = "api",
107
+ [ApiTimeout] = "api",
108
+ [ApiUnavailable] = "api",
109
+ [IpcTransport] = "ipc",
110
+ [IpcProtocol] = "ipc",
111
+ [IpcTimeout] = "ipc",
112
+ [IpcAuth] = "ipc",
113
+ [IpcDisconnected] = "ipc",
114
+ [IpcBackpressure] = "ipc",
115
+ [CodegenUnsupported] = "codegen",
116
+ [CodegenEmit] = "codegen",
117
+ [CodegenRoundtrip] = "codegen",
118
+ [CssParse] = "css",
119
+ [CssUnsupportedProperty] = "css",
120
+ [CssUnsupportedSelector] = "css",
121
+ [NativeModuleNotFound] = "native",
122
+ [NativeMethodNotFound] = "native",
123
+ [NativeCallFailed] = "native",
124
+ [BuildFailed] = "build",
125
+ [BuildToolMissing] = "build",
126
+ [PackageFailed] = "package",
127
+ [PackageSigning] = "package",
128
+ [SettingsParse] = "settings",
129
+ [SettingsInvalid] = "settings",
130
+ [PathInvalid] = "path",
131
+ [PathAbsolute] = "path",
132
+ };
133
+
134
+ /// <summary>Whether <paramref name="code"/> is one of the known stable codes.</summary>
135
+ public static bool IsKnown(string? code) => code is not null && CategoryByCode.ContainsKey(code);
136
+
137
+ /// <summary>The category a code belongs to, or <c>"general"</c> when unknown.</summary>
138
+ public static string CategoryOf(string? code) =>
139
+ code is not null && CategoryByCode.TryGetValue(code, out var category) ? category : "general";
140
+ }
141
+
142
+ /// <summary>
143
+ /// Base exception for every error defined by this package.
144
+ /// Mirrors <c>TochiResError</c> from the TypeScript implementation.
145
+ /// </summary>
146
+ public class TochiResException : Exception
147
+ {
148
+ /// <summary>Stable error code — part of the public contract.</summary>
149
+ public string Code { get; }
150
+
151
+ /// <summary>Coarse category derived from <see cref="Code"/>.</summary>
152
+ public string Category { get; }
153
+
154
+ /// <summary>Structured, JSON-safe context for logging and telemetry.</summary>
155
+ public IReadOnlyDictionary<string, object?>? Context { get; }
156
+
157
+ public TochiResException(
158
+ string code,
159
+ string message,
160
+ Exception? innerException = null,
161
+ IReadOnlyDictionary<string, object?>? context = null)
162
+ : base(message, innerException)
163
+ {
164
+ Code = code;
165
+ Category = ErrorCodes.CategoryOf(code);
166
+ Context = context;
167
+ }
168
+ }
169
+
170
+ /// <summary>Configuration is missing or failed validation.</summary>
171
+ public sealed class ConfigException : TochiResException
172
+ {
173
+ public ConfigException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
174
+ : base(ErrorCodes.ConfigInvalid, message, inner, context) { }
175
+
176
+ public ConfigException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
177
+ : base(code, message, inner, context) { }
178
+ }
179
+
180
+ /// <summary>A payload, schema or argument failed validation.</summary>
181
+ public sealed class ValidationException : TochiResException
182
+ {
183
+ public ValidationException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
184
+ : base(ErrorCodes.ValidationFailed, message, inner, context) { }
185
+ }
186
+
187
+ /// <summary>An API/HTTP boundary failure (bad request, auth, not found, conflict, …).</summary>
188
+ public sealed class ApiException : TochiResException
189
+ {
190
+ public ApiException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
191
+ : base(ErrorCodes.ApiBadRequest, message, inner, context) { }
192
+
193
+ public ApiException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
194
+ : base(code, message, inner, context) { }
195
+ }
196
+
197
+ /// <summary>An IPC transport, protocol, authentication or timeout failure.</summary>
198
+ public sealed class IpcException : TochiResException
199
+ {
200
+ public IpcException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
201
+ : base(ErrorCodes.IpcTransport, message, inner, context) { }
202
+
203
+ public IpcException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
204
+ : base(code, message, inner, context) { }
205
+ }
206
+
207
+ /// <summary>A TS→C# code generator failed or hit an unsupported construct.</summary>
208
+ public sealed class CodegenException : TochiResException
209
+ {
210
+ public CodegenException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
211
+ : base(ErrorCodes.CodegenEmit, message, inner, context) { }
212
+
213
+ public CodegenException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
214
+ : base(code, message, inner, context) { }
215
+ }
216
+
217
+ /// <summary>CSS input is invalid or outside the supported subset.</summary>
218
+ public sealed class CssException : TochiResException
219
+ {
220
+ public CssException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
221
+ : base(ErrorCodes.CssParse, message, inner, context) { }
222
+
223
+ public CssException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
224
+ : base(code, message, inner, context) { }
225
+ }
226
+
227
+ /// <summary>A native module or method was missing, or a native call failed.</summary>
228
+ public sealed class NativeException : TochiResException
229
+ {
230
+ public NativeException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
231
+ : base(ErrorCodes.NativeCallFailed, message, inner, context) { }
232
+
233
+ public NativeException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
234
+ : base(code, message, inner, context) { }
235
+ }
236
+
237
+ /// <summary>A build pipeline step failed or a required tool is missing.</summary>
238
+ public sealed class BuildException : TochiResException
239
+ {
240
+ public BuildException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
241
+ : base(ErrorCodes.BuildFailed, message, inner, context) { }
242
+
243
+ public BuildException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
244
+ : base(code, message, inner, context) { }
245
+ }
246
+
247
+ /// <summary>A packaging, signing or notarization step failed.</summary>
248
+ public sealed class PackageException : TochiResException
249
+ {
250
+ public PackageException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
251
+ : base(ErrorCodes.PackageFailed, message, inner, context) { }
252
+
253
+ public PackageException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
254
+ : base(code, message, inner, context) { }
255
+ }
256
+
257
+ /// <summary>Settings text could not be parsed or failed validation.</summary>
258
+ public sealed class SettingsException : TochiResException
259
+ {
260
+ public SettingsException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
261
+ : base(ErrorCodes.SettingsInvalid, message, inner, context) { }
262
+
263
+ public SettingsException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
264
+ : base(code, message, inner, context) { }
265
+ }
266
+
267
+ /// <summary>A path was malformed or violated the relative-path rule.</summary>
268
+ public sealed class PathException : TochiResException
269
+ {
270
+ public PathException(string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
271
+ : base(ErrorCodes.PathInvalid, message, inner, context) { }
272
+
273
+ public PathException(string code, string message, Exception? inner = null, IReadOnlyDictionary<string, object?>? context = null)
274
+ : base(code, message, inner, context) { }
275
+ }
package/package.json CHANGED
@@ -1,57 +1,56 @@
1
1
  {
2
- "name": "@tochii/errors",
3
- "version": "0.1.2",
4
- "description": "Shared typed errors and stable error codes used in official tochiResources proejcts.",
5
- "license": "MIT",
6
- "author": "T0chi",
7
- "type": "module",
8
- "private": false,
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/tochiResources/errors.git"
12
- },
13
- "scripts": {
14
- "build": "tsdown --config-loader unrun",
15
- "format": "dbx fmt",
16
- "lint": "dbx lint --fix",
17
- "check": "dbx check",
18
- "test": "vitest run",
19
- "typecheck": "tsc -p tsconfig.build.json --noEmit",
20
- "dbx": "dbx",
21
- "commitlint": "commitlint",
22
- "prepare": "husky"
23
- },
24
- "devDependencies": {
25
- "@commitlint/cli": "^21.2.2",
26
- "@commitlint/config-conventional": "^21.2.2",
27
- "@deltabox/toolchain": "^1.11.3",
28
- "@types/node": "catalog:",
29
- "@typescript/native-preview": "catalog:",
30
- "husky": "^9.1.7",
31
- "tsdown": "catalog:",
32
- "tsx": "catalog:",
33
- "typescript": "catalog:",
34
- "unrun": "^0.3.1",
35
- "vite": "catalog:",
36
- "vite-plus": "^1.2.0",
37
- "vitest": "catalog:"
38
- },
39
- "publishConfig": {
40
- "access": "public"
41
- },
42
- "packageManager": "yarn@4.17.1",
43
- "engines": {
44
- "node": ">=22.5.0"
45
- },
46
- "files": [
47
- "dist",
48
- "csharp"
49
- ],
50
- "types": "./dist/index.d.ts",
51
- "exports": {
52
- ".": "./dist/index.js",
53
- "./codes": "./dist/codes.js",
54
- "./serialize": "./dist/serialize.js",
55
- "./package.json": "./package.json"
56
- }
57
- }
2
+ "name": "@tochii/errors",
3
+ "version": "0.1.8",
4
+ "description": "Shared typed errors and stable error codes used in official tochiResources proejcts.",
5
+ "license": "MIT",
6
+ "author": "T0chi",
7
+ "type": "module",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/tochiResources/errors.git"
11
+ },
12
+ "scripts": {
13
+ "build": "tsdown --config-loader unrun",
14
+ "format": "dbx fmt",
15
+ "lint": "dbx lint --fix",
16
+ "check": "dbx check",
17
+ "test": "vitest run",
18
+ "typecheck": "tsc -p tsconfig.build.json --noEmit",
19
+ "dbx": "dbx",
20
+ "commitlint": "commitlint",
21
+ "prepare": "husky"
22
+ },
23
+ "devDependencies": {
24
+ "@commitlint/cli": "^21.2.2",
25
+ "@commitlint/config-conventional": "^21.2.2",
26
+ "@deltabox/toolchain": "^1.11.3",
27
+ "@types/node": "^22.10.2",
28
+ "@typescript/native-preview": "7.0.0-dev.20260707.2",
29
+ "husky": "^9.1.7",
30
+ "tsdown": "^0.23.0",
31
+ "tsx": "^4.23.13",
32
+ "typescript": "^6.0.3",
33
+ "unrun": "^0.3.1",
34
+ "vite": "^8.3.0",
35
+ "vite-plus": "^1.2.0",
36
+ "vitest": "^5.0.0"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "packageManager": "yarn@4.17.1",
42
+ "engines": {
43
+ "node": ">=22.5.0"
44
+ },
45
+ "files": [
46
+ "dist",
47
+ "csharp"
48
+ ],
49
+ "types": "./dist/index.d.ts",
50
+ "exports": {
51
+ ".": "./dist/index.js",
52
+ "./codes": "./dist/codes.js",
53
+ "./serialize": "./dist/serialize.js",
54
+ "./package.json": "./package.json"
55
+ }
56
+ }