Skip to content

Commit b1a778c

Browse files
committed
feat: Initial error imrprovement change. Add support for Apply Validation Error.
1 parent 2c257f2 commit b1a778c

3 files changed

Lines changed: 43 additions & 13 deletions

File tree

package-lock.json

Lines changed: 22 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codifycli/plugin-core",
3-
"version": "1.1.0-beta16",
3+
"version": "1.1.0-beta18",
44
"description": "TypeScript library for building Codify plugins to manage system resources (applications, CLI tools, settings) through infrastructure-as-code",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -35,7 +35,7 @@
3535
},
3636
"license": "ISC",
3737
"dependencies": {
38-
"@codifycli/schemas": "1.1.0-beta6",
38+
"@codifycli/schemas": "^1.1.0-beta7",
3939
"@homebridge/node-pty-prebuilt-multiarch": "^0.13.1",
4040
"ajv": "^8.18.0",
4141
"ajv-formats": "^2.1.1",

src/messages/handlers.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
ApplyRequestDataSchema,
33
EmptyResponseDataSchema,
4+
ErrorCode,
45
GetResourceInfoRequestDataSchema,
56
GetResourceInfoResponseDataSchema,
67
ImportRequestDataSchema,
@@ -24,6 +25,7 @@ import {
2425
import { Ajv, SchemaObject, ValidateFunction } from 'ajv';
2526
import addFormats from 'ajv-formats';
2627

28+
import { ApplyValidationError } from '../common/errors.js';
2729
import { SudoError } from '../errors.js';
2830
import { Plugin } from '../plugin/plugin.js';
2931

@@ -168,13 +170,29 @@ export class MessageHandler {
168170
})
169171
}
170172

173+
if (e instanceof ApplyValidationError) {
174+
return process.send?.({
175+
cmd,
176+
// @ts-expect-error TS2239
177+
requestId: message.requestId || undefined,
178+
data: {
179+
errorCode: ErrorCode.APPLY_VALIDATION,
180+
plan: e.plan.toResponse(),
181+
},
182+
status: MessageStatus.ERROR,
183+
});
184+
}
185+
171186
const isDebug = process.env.DEBUG?.includes('*') ?? false;
172187

173188
process.send?.({
174189
cmd,
175190
// @ts-expect-error TS2239
176191
requestId: message.requestId || undefined,
177-
data: isDebug ? e.stack : e.message,
192+
data: {
193+
errorCode: ErrorCode.UNKNOWN,
194+
message: isDebug ? (e.stack ?? e.message) : e.message,
195+
},
178196
status: MessageStatus.ERROR,
179197
})
180198
}

0 commit comments

Comments
 (0)