Skip to content

Commit fe6203a

Browse files
committed
refactor(errors): use dedicated MANIFEST_VALIDATION_ERROR code for skills.json validation
- Add new error code EMANIFESTVAL for manifest validation errors - Use ManifestError instead of SkillError for validation failures - Add helpful error message pointing to JSON Schema reference
1 parent 78fd718 commit fe6203a

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

packages/skills-package-manager/src/config/readSkillsManifest.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { readFile } from 'node:fs/promises'
22
import path from 'node:path'
3-
import { convertNodeError, ErrorCode, ParseError, SkillError } from '../errors'
3+
import { convertNodeError, ErrorCode, ManifestError, ParseError } from '../errors'
44
import { skillsManifestSchema } from './schema'
55
import type { SkillsManifest } from './types'
66

@@ -28,9 +28,9 @@ export async function readSkillsManifest(rootDir: string): Promise<SkillsManifes
2828
const issues = result.error.issues
2929
.map((issue) => `${issue.path.join('.')}: ${issue.message}`)
3030
.join('\n - ')
31-
throw new SkillError({
32-
code: ErrorCode.VALIDATION_ERROR,
33-
skillName: 'manifest',
31+
throw new ManifestError({
32+
code: ErrorCode.MANIFEST_VALIDATION_ERROR,
33+
filePath,
3434
message: `Invalid skills.json:\n - ${issues}`,
3535
})
3636
}
@@ -40,7 +40,7 @@ export async function readSkillsManifest(rootDir: string): Promise<SkillsManifes
4040
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
4141
return null
4242
}
43-
if (error instanceof ParseError || error instanceof SkillError) {
43+
if (error instanceof ParseError || error instanceof ManifestError) {
4444
throw error
4545
}
4646
throw convertNodeError(error as NodeJS.ErrnoException, { operation: 'read', path: filePath })

packages/skills-package-manager/src/errors/codes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export enum ErrorCode {
2727
LOCKFILE_NOT_FOUND = 'ELOCKFILE',
2828
LOCKFILE_OUTDATED = 'ELOCKOUTDATED',
2929
MANIFEST_EXISTS = 'EMANIFESTEXISTS',
30+
MANIFEST_VALIDATION_ERROR = 'EMANIFESTVAL',
3031

3132
// Network/Remote errors (5xx)
3233
NETWORK_ERROR = 'ENETWORK',

packages/skills-package-manager/src/errors/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ export function formatErrorForDisplay(error: unknown): string {
124124
if (error.code === ErrorCode.LOCKFILE_OUTDATED) {
125125
output += `\n\nThe lockfile is out of sync with skills.json.`
126126
output += `\nRun "spm install" to update the lockfile.`
127+
} else if (error.code === ErrorCode.MANIFEST_VALIDATION_ERROR) {
128+
output += `\n\nPlease fix the validation errors in "${error.filePath}".`
129+
output += `\nRefer to the JSON Schema at: https://unpkg.com/skills-package-manager@latest/skills.schema.json`
127130
}
128131
}
129132

packages/skills-package-manager/src/errors/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export class ManifestError extends SpmError {
114114
| ErrorCode.LOCKFILE_NOT_FOUND
115115
| ErrorCode.LOCKFILE_OUTDATED
116116
| ErrorCode.MANIFEST_EXISTS
117+
| ErrorCode.MANIFEST_VALIDATION_ERROR
117118
filePath: string
118119
message?: string
119120
cause?: Error
@@ -123,6 +124,7 @@ export class ManifestError extends SpmError {
123124
[ErrorCode.LOCKFILE_NOT_FOUND]: `Lockfile not found: ${options.filePath}`,
124125
[ErrorCode.LOCKFILE_OUTDATED]: `Lockfile is out of date: ${options.filePath}`,
125126
[ErrorCode.MANIFEST_EXISTS]: `Manifest already exists: ${options.filePath}`,
127+
[ErrorCode.MANIFEST_VALIDATION_ERROR]: `Invalid skills.json: ${options.filePath}`,
126128
}
127129
const message =
128130
options.message ?? defaultMessages[options.code] ?? `Manifest error: ${options.filePath}`

0 commit comments

Comments
 (0)