MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / classifyImageError

Function classifyImageError

source code/utils/imageResizer.ts:52–126  ·  view source on GitHub ↗

* Classifies image processing errors for analytics. * * Uses error codes when available (Node.js module errors), falls back to * message matching for libraries like sharp that don't expose error codes.

(error: unknown)

Source from the content-addressed store, hash-verified

50 * message matching for libraries like sharp that don't expose error codes.
51 */
52function classifyImageError(error: unknown): number {
53 // Check for Node.js error codes first (more reliable than string matching)
54 if (error instanceof Error) {
55 const errorWithCode = error as Error & { code?: string }
56 if (
57 errorWithCode.code === 'MODULE_NOT_FOUND' ||
58 errorWithCode.code === 'ERR_MODULE_NOT_FOUND' ||
59 errorWithCode.code === 'ERR_DLOPEN_FAILED'
60 ) {
61 return ERROR_TYPE_MODULE_LOAD
62 }
63 if (errorWithCode.code === 'EACCES' || errorWithCode.code === 'EPERM') {
64 return ERROR_TYPE_PERMISSION
65 }
66 if (errorWithCode.code === 'ENOMEM') {
67 return ERROR_TYPE_MEMORY
68 }
69 }
70
71 // Fall back to message matching for errors without codes
72 // Note: sharp doesn't expose error codes, so we must match on messages
73 const message = errorMessage(error)
74
75 // Module loading errors from our native wrapper
76 if (message.includes('Native image processor module not available')) {
77 return ERROR_TYPE_MODULE_LOAD
78 }
79
80 // Sharp/vips processing errors (format detection, corrupt data, etc.)
81 if (
82 message.includes('unsupported image format') ||
83 message.includes('Input buffer') ||
84 message.includes('Input file is missing') ||
85 message.includes('Input file has corrupt header') ||
86 message.includes('corrupt header') ||
87 message.includes('corrupt image') ||
88 message.includes('premature end') ||
89 message.includes('zlib: data error') ||
90 message.includes('zero width') ||
91 message.includes('zero height')
92 ) {
93 return ERROR_TYPE_PROCESSING
94 }
95
96 // Pixel/dimension limit errors from sharp/vips
97 if (
98 message.includes('pixel limit') ||
99 message.includes('too many pixels') ||
100 message.includes('exceeds pixel') ||
101 message.includes('image dimensions')
102 ) {
103 return ERROR_TYPE_PIXEL_LIMIT
104 }
105
106 // Memory allocation failures
107 if (
108 message.includes('out of memory') ||
109 message.includes('Cannot allocate') ||

Callers 2

compressImageBufferFunction · 0.85

Calls 1

errorMessageFunction · 0.70

Tested by

no test coverage detected