|
|
@@ -1,5 +1,31 @@
|
|
|
/** Attachment failure class. @module @deepseek-ai/dsh-attachment/error */
|
|
|
|
|
|
+const IMAGE_ADMISSION_ERROR_CODES = [
|
|
|
+ 'TOO_MANY_IMAGES',
|
|
|
+ 'IMAGES_TOO_LARGE',
|
|
|
+ 'UNSUPPORTED_IMAGE_TYPE',
|
|
|
+ 'INVALID_IMAGE_BASE64',
|
|
|
+ 'INVALID_IMAGE',
|
|
|
+ 'IMAGE_TYPE_MISMATCH',
|
|
|
+ 'IMAGE_TOO_LARGE',
|
|
|
+ 'IMAGE_TOO_MANY_PIXELS',
|
|
|
+] as const
|
|
|
+
|
|
|
+/** Caller-correctable attachment failure codes raised while admitting image input. */
|
|
|
+export type ImageAdmissionErrorCode = typeof IMAGE_ADMISSION_ERROR_CODES[number]
|
|
|
+
|
|
|
+/** Stable attachment failure codes used for protocol error routing. */
|
|
|
+export type AttachmentErrorCode =
|
|
|
+ | ImageAdmissionErrorCode
|
|
|
+ | 'INVALID_ATTACHMENT_REF'
|
|
|
+ | 'ATTACHMENT_CORRUPT'
|
|
|
+ | 'ATTACHMENT_WRITE_FAILED'
|
|
|
+ | 'ATTACHMENT_NOT_FOUND'
|
|
|
+ | 'ATTACHMENT_READ_FAILED'
|
|
|
+
|
|
|
+/** Runtime membership for structurally compatible errors crossing package boundaries. */
|
|
|
+const IMAGE_ADMISSION_ERROR_CODE_SET: ReadonlySet<string> = new Set(IMAGE_ADMISSION_ERROR_CODES)
|
|
|
+
|
|
|
/**
|
|
|
* Stable failures suitable for host RPC error mapping.
|
|
|
*
|
|
|
@@ -11,39 +37,30 @@
|
|
|
*/
|
|
|
export class AttachmentError extends Error {
|
|
|
/** Stable machine-routing failure code. */
|
|
|
- readonly code: string
|
|
|
+ readonly code: AttachmentErrorCode
|
|
|
|
|
|
/**
|
|
|
* @param message - human-readable failure description without raw bytes or host paths.
|
|
|
* @param code - stable machine-routing code.
|
|
|
* @param options - optional chained cause.
|
|
|
*/
|
|
|
- constructor(message: string, code: string, options?: ErrorOptions) {
|
|
|
+ constructor(message: string, code: AttachmentErrorCode, options?: ErrorOptions) {
|
|
|
super(message, options)
|
|
|
this.name = 'AttachmentError'
|
|
|
this.code = code
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/** Attachment failures caused by the caller's proposed image batch. */
|
|
|
-const IMAGE_ADMISSION_ERROR_CODES = new Set([
|
|
|
- 'TOO_MANY_IMAGES',
|
|
|
- 'IMAGES_TOO_LARGE',
|
|
|
- 'UNSUPPORTED_IMAGE_TYPE',
|
|
|
- 'INVALID_IMAGE',
|
|
|
- 'IMAGE_TYPE_MISMATCH',
|
|
|
- 'IMAGE_TOO_LARGE',
|
|
|
- 'IMAGE_TOO_MANY_PIXELS',
|
|
|
-])
|
|
|
-
|
|
|
/**
|
|
|
* Distinguish caller-correctable image admission failures from storage faults.
|
|
|
* @param error - failure raised while validating or persisting an image batch.
|
|
|
* @returns whether the caller can correct the proposed image content or batch.
|
|
|
*/
|
|
|
-export function isImageAdmissionError(error: unknown): error is AttachmentError {
|
|
|
+export function isImageAdmissionError(
|
|
|
+ error: unknown,
|
|
|
+): error is AttachmentError & { readonly code: ImageAdmissionErrorCode } {
|
|
|
return error instanceof Error
|
|
|
&& 'code' in error
|
|
|
&& typeof error.code === 'string'
|
|
|
- && IMAGE_ADMISSION_ERROR_CODES.has(error.code)
|
|
|
+ && IMAGE_ADMISSION_ERROR_CODE_SET.has(error.code)
|
|
|
}
|