@hkdigital/lib-core 0.4.20 → 0.4.22

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.
@@ -262,7 +262,7 @@ export class ConsoleAdapter {
262
262
  let current = err;
263
263
  let isFirst = true;
264
264
 
265
- while (current) {
265
+ while (current && current instanceof Error) {
266
266
  // Check if this is the first error and it's a LoggerError - extract logging context
267
267
  if (isFirst && current.name === 'LoggerError') {
268
268
  if (current.stack) {
@@ -393,6 +393,12 @@ export class ConsoleAdapter {
393
393
  continue;
394
394
  }
395
395
 
396
+ // Skip internal logger methods
397
+ if (cleaned.includes('#toError@') ||
398
+ (cleaned.includes('logger/Logger.js') && cleaned.includes('#toError'))) {
399
+ continue;
400
+ }
401
+
396
402
  relevantFrames.push(cleaned);
397
403
 
398
404
  // Limit to first 15 relevant frames to see more
@@ -1,9 +1,3 @@
1
- /**
2
- * Shared error formatting logic for logging adapters
3
- *
4
- * This module contains reusable functions for analyzing and formatting
5
- * errors with enhanced stack trace detection and error type identification.
6
- */
7
1
  /**
8
2
  * Find the most relevant frame index for highlighting in stack traces
9
3
  *
@@ -50,9 +44,10 @@ export function getHttpMethod(cleanedStack: string[]): string | null;
50
44
  *
51
45
  * @param {Error} error - The error object
52
46
  * @param {string[]} cleanedStack - Array of cleaned stack trace frames
47
+ * @param {number} [relevantFrameIndex] - Pre-computed relevant frame index to use
53
48
  * @returns {string|null} User function name or null
54
49
  */
55
- export function extractUserFunctionName(error: Error, cleanedStack: string[]): string | null;
50
+ export function extractUserFunctionName(error: Error, cleanedStack: string[], relevantFrameIndex?: number): string | null;
56
51
  /**
57
52
  * Check if function name is meaningful (not anonymous or framework code)
58
53
  *
@@ -1,22 +1,43 @@
1
1
  /**
2
2
  * Shared error formatting logic for logging adapters
3
- *
3
+ *
4
4
  * This module contains reusable functions for analyzing and formatting
5
5
  * errors with enhanced stack trace detection and error type identification.
6
6
  */
7
7
 
8
+ import * as is from '../../../util/is.js';
9
+
8
10
  /**
9
11
  * Find the most relevant frame index for highlighting in stack traces
10
- *
12
+ *
11
13
  * @param {Error} error - The error object
12
14
  * @param {string[]} cleanedStack - Array of cleaned stack trace frames
13
15
  * @returns {number} Index of the most relevant frame to highlight
14
16
  */
15
17
  export function findRelevantFrameIndex(error, cleanedStack) {
18
+ // Check for SvelteKit HttpError - look for action pattern
19
+ if (
20
+ error.name === 'HttpError' &&
21
+ error.cause &&
22
+ is.SveltekitHttpError(error.cause)
23
+ ) {
24
+ const svelteKitActionsIndex = cleanedStack.findIndex((frame) =>
25
+ frame.includes(
26
+ 'node_modules/@sveltejs/kit/src/runtime/server/page/actions.js'
27
+ )
28
+ );
29
+ if (svelteKitActionsIndex >= 1) {
30
+ // Return the frame before the SvelteKit actions.js frame
31
+ // This should be the actual server action function where throw error() was called
32
+ return svelteKitActionsIndex - 1;
33
+ }
34
+ }
35
+
16
36
  // Check if this is a LoggerError - look for Logger.error call
17
37
  if (error.name === 'LoggerError') {
18
- const loggerErrorIndex = cleanedStack.findIndex(frame =>
19
- frame.includes('Logger.error') && frame.includes('logger/Logger.js')
38
+ const loggerErrorIndex = cleanedStack.findIndex(
39
+ (frame) =>
40
+ frame.includes('Logger.error') && frame.includes('logger/Logger.js')
20
41
  );
21
42
  if (loggerErrorIndex >= 0 && loggerErrorIndex + 1 < cleanedStack.length) {
22
43
  return loggerErrorIndex + 1;
@@ -25,15 +46,17 @@ export function findRelevantFrameIndex(error, cleanedStack) {
25
46
 
26
47
  if (error.name === 'ValiError') {
27
48
  // Look for expect_ function first, user code is right after (handle Node.js format)
28
- const expectIndex = cleanedStack.findIndex(frame =>
29
- frame.includes('expect_') || frame.includes('Module.expect_')
49
+ const expectIndex = cleanedStack.findIndex(
50
+ (frame) => frame.includes('expect_') || frame.includes('Module.expect_')
30
51
  );
31
52
  if (expectIndex >= 0 && expectIndex + 1 < cleanedStack.length) {
32
53
  return expectIndex + 1;
33
54
  }
34
-
55
+
35
56
  // If no expect_ function, look for valibotParser, user code is right after
36
- const valibotIndex = cleanedStack.findIndex(frame => frame.includes('valibotParser'));
57
+ const valibotIndex = cleanedStack.findIndex((frame) =>
58
+ frame.includes('valibotParser')
59
+ );
37
60
  if (valibotIndex >= 0 && valibotIndex + 1 < cleanedStack.length) {
38
61
  return valibotIndex + 1;
39
62
  }
@@ -42,17 +65,19 @@ export function findRelevantFrameIndex(error, cleanedStack) {
42
65
  if (error.name === 'DetailedError') {
43
66
  // Check if this DetailedError was created by Logger.error - look for Logger.error call first
44
67
  // Handle both Firefox format (error@file) and Node.js format (at Logger.error (file))
45
- const loggerErrorIndex = cleanedStack.findIndex(frame =>
46
- (frame.includes('Logger.error') && frame.includes('logger/Logger.js')) ||
47
- (frame.includes('error@') && frame.includes('logger/Logger.js'))
68
+ const loggerErrorIndex = cleanedStack.findIndex(
69
+ (frame) =>
70
+ (frame.includes('Logger.error') &&
71
+ frame.includes('logger/Logger.js')) ||
72
+ (frame.includes('error@') && frame.includes('logger/Logger.js'))
48
73
  );
49
74
  if (loggerErrorIndex >= 0 && loggerErrorIndex + 1 < cleanedStack.length) {
50
75
  return loggerErrorIndex + 1;
51
76
  }
52
-
77
+
53
78
  // Look for rethrow, user code is right after (handle both Firefox and Node.js format)
54
- const rethrowIndex = cleanedStack.findIndex(frame =>
55
- frame.includes('rethrow@') || frame.includes('at rethrow (')
79
+ const rethrowIndex = cleanedStack.findIndex(
80
+ (frame) => frame.includes('rethrow@') || frame.includes('at rethrow (')
56
81
  );
57
82
  if (rethrowIndex >= 0 && rethrowIndex + 1 < cleanedStack.length) {
58
83
  return rethrowIndex + 1;
@@ -61,12 +86,13 @@ export function findRelevantFrameIndex(error, cleanedStack) {
61
86
 
62
87
  if (error.name === 'PromiseError') {
63
88
  // Look for HkPromise methods, user code is right after
64
- const hkPromiseIndex = cleanedStack.findIndex(frame =>
65
- frame.includes('reject@') ||
66
- frame.includes('tryReject@') ||
67
- frame.includes('setTimeout@') ||
68
- frame.includes('cancel@') ||
69
- frame.includes('tryCancel@')
89
+ const hkPromiseIndex = cleanedStack.findIndex(
90
+ (frame) =>
91
+ frame.includes('reject@') ||
92
+ frame.includes('tryReject@') ||
93
+ frame.includes('setTimeout@') ||
94
+ frame.includes('cancel@') ||
95
+ frame.includes('tryCancel@')
70
96
  );
71
97
  if (hkPromiseIndex >= 0 && hkPromiseIndex + 1 < cleanedStack.length) {
72
98
  return hkPromiseIndex + 1;
@@ -92,14 +118,18 @@ export function findRelevantFrameIndex(error, cleanedStack) {
92
118
 
93
119
  /**
94
120
  * Detect error metadata for structured logging and display
95
- *
121
+ *
96
122
  * @param {Error} error - The error object
97
123
  * @param {string[]} cleanedStack - Array of cleaned stack trace frames
98
124
  * @returns {import('./typedef.js').ErrorSummaryMeta} Error metadata
99
125
  */
100
126
  export function detectErrorMeta(error, cleanedStack) {
101
- const userFunctionName = extractUserFunctionName(error, cleanedStack);
102
127
  const relevantFrameIndex = findRelevantFrameIndex(error, cleanedStack);
128
+ const userFunctionName = extractUserFunctionName(
129
+ error,
130
+ cleanedStack,
131
+ relevantFrameIndex
132
+ );
103
133
 
104
134
  // Check if it's a LoggerError
105
135
  if (error.name === 'LoggerError') {
@@ -115,11 +145,13 @@ export function detectErrorMeta(error, cleanedStack) {
115
145
  if (error.name === 'DetailedError') {
116
146
  // Check if this DetailedError was created by Logger.error
117
147
  const cleanedStackArray = cleanedStack || [];
118
- const loggerErrorIndex = cleanedStackArray.findIndex(frame =>
119
- (frame.includes('Logger.error') && frame.includes('logger/Logger.js')) ||
120
- (frame.includes('error@') && frame.includes('logger/Logger.js'))
148
+ const loggerErrorIndex = cleanedStackArray.findIndex(
149
+ (frame) =>
150
+ (frame.includes('Logger.error') &&
151
+ frame.includes('logger/Logger.js')) ||
152
+ (frame.includes('error@') && frame.includes('logger/Logger.js'))
121
153
  );
122
-
154
+
123
155
  if (loggerErrorIndex >= 0) {
124
156
  return {
125
157
  category: 'logger',
@@ -128,7 +160,7 @@ export function detectErrorMeta(error, cleanedStack) {
128
160
  relevantFrameIndex
129
161
  };
130
162
  }
131
-
163
+
132
164
  // Otherwise it's a regular rethrow error
133
165
  return {
134
166
  category: 'rethrow',
@@ -163,15 +195,15 @@ export function detectErrorMeta(error, cleanedStack) {
163
195
  // Check if it's a valibot validation error
164
196
  if (error.name === 'ValiError' && cleanedStack.length > 0) {
165
197
  // Look for our valibotParser wrapper function in the stack
166
- const valibotFrame = cleanedStack.find(frame =>
198
+ const valibotFrame = cleanedStack.find((frame) =>
167
199
  frame.includes('valibotParser')
168
200
  );
169
-
201
+
170
202
  // Also check if it's called via an expect_ function (handle Node.js format)
171
- const expectFrame = cleanedStack.find(frame =>
172
- frame.includes('expect_') || frame.includes('Module.expect_')
203
+ const expectFrame = cleanedStack.find(
204
+ (frame) => frame.includes('expect_') || frame.includes('Module.expect_')
173
205
  );
174
-
206
+
175
207
  if (valibotFrame || expectFrame) {
176
208
  return {
177
209
  category: 'validation',
@@ -193,7 +225,7 @@ export function detectErrorMeta(error, cleanedStack) {
193
225
 
194
226
  /**
195
227
  * Format error metadata for console display
196
- *
228
+ *
197
229
  * @param {{category: string, method: string, origin?: string|null}} errorMeta - Error metadata
198
230
  * @returns {string} Formatted display string (e.g., "httpGet in myFunction")
199
231
  */
@@ -206,43 +238,44 @@ export function formatErrorDisplay(errorMeta) {
206
238
 
207
239
  /**
208
240
  * Get the specific HkPromise method that caused the error
209
- *
241
+ *
210
242
  * @param {string[]} cleanedStack - Array of cleaned stack trace frames
211
243
  * @returns {string|null} HkPromise method name or null
212
244
  */
213
245
  export function getHkPromiseMethod(cleanedStack) {
214
- const hkPromiseFrame = cleanedStack.find(frame =>
215
- frame.includes('reject@') ||
216
- frame.includes('tryReject@') ||
217
- frame.includes('setTimeout@') ||
218
- frame.includes('cancel@') ||
219
- frame.includes('tryCancel@')
246
+ const hkPromiseFrame = cleanedStack.find(
247
+ (frame) =>
248
+ frame.includes('reject@') ||
249
+ frame.includes('tryReject@') ||
250
+ frame.includes('setTimeout@') ||
251
+ frame.includes('cancel@') ||
252
+ frame.includes('tryCancel@')
220
253
  );
221
-
254
+
222
255
  if (!hkPromiseFrame) return null;
223
-
256
+
224
257
  if (hkPromiseFrame.includes('reject@')) return 'reject';
225
258
  if (hkPromiseFrame.includes('tryReject@')) return 'tryReject';
226
259
  if (hkPromiseFrame.includes('setTimeout@')) return 'setTimeout';
227
260
  if (hkPromiseFrame.includes('cancel@')) return 'cancel';
228
261
  if (hkPromiseFrame.includes('tryCancel@')) return 'tryCancel';
229
-
262
+
230
263
  return null;
231
264
  }
232
265
 
233
266
  /**
234
267
  * Get the specific HTTP method that caused the error
235
- *
268
+ *
236
269
  * @param {string[]} cleanedStack - Array of cleaned stack trace frames
237
270
  * @returns {string|null} HTTP method name or null
238
271
  */
239
272
  export function getHttpMethod(cleanedStack) {
240
- const httpFrame = cleanedStack.find(frame =>
273
+ const httpFrame = cleanedStack.find((frame) =>
241
274
  frame.includes('network/http/http-request.js')
242
275
  );
243
-
276
+
244
277
  if (!httpFrame) return null;
245
-
278
+
246
279
  if (httpFrame.includes('httpGet@')) return 'httpGet';
247
280
  if (httpFrame.includes('httpPost@')) return 'httpPost';
248
281
  if (httpFrame.includes('httpPut@')) return 'httpPut';
@@ -250,22 +283,32 @@ export function getHttpMethod(cleanedStack) {
250
283
  if (httpFrame.includes('httpPatch@')) return 'httpPatch';
251
284
  if (httpFrame.includes('httpOptions@')) return 'httpOptions';
252
285
  if (httpFrame.includes('httpRequest@')) return 'httpRequest';
253
-
286
+
254
287
  return null;
255
288
  }
256
289
 
257
290
  /**
258
291
  * Extract user function name from stack trace
259
- *
292
+ *
260
293
  * @param {Error} error - The error object
261
294
  * @param {string[]} cleanedStack - Array of cleaned stack trace frames
295
+ * @param {number} [relevantFrameIndex] - Pre-computed relevant frame index to use
262
296
  * @returns {string|null} User function name or null
263
297
  */
264
- export function extractUserFunctionName(error, cleanedStack) {
298
+ export function extractUserFunctionName(
299
+ error,
300
+ cleanedStack,
301
+ relevantFrameIndex
302
+ ) {
303
+ // If we have a pre-computed relevant frame index, use it
304
+ if (relevantFrameIndex >= 0 && relevantFrameIndex < cleanedStack.length) {
305
+ return parseFunctionName(cleanedStack[relevantFrameIndex]);
306
+ }
265
307
  // Check if this is a LoggerError - look for the frame after Logger.error
266
308
  if (error.name === 'LoggerError' && cleanedStack.length > 1) {
267
- const loggerErrorIndex = cleanedStack.findIndex(frame =>
268
- frame.includes('Logger.error') && frame.includes('logger/Logger.js')
309
+ const loggerErrorIndex = cleanedStack.findIndex(
310
+ (frame) =>
311
+ frame.includes('Logger.error') && frame.includes('logger/Logger.js')
269
312
  );
270
313
  if (loggerErrorIndex >= 0 && loggerErrorIndex + 1 < cleanedStack.length) {
271
314
  return parseFunctionName(cleanedStack[loggerErrorIndex + 1]);
@@ -274,17 +317,19 @@ export function extractUserFunctionName(error, cleanedStack) {
274
317
 
275
318
  if (error.name === 'DetailedError' && cleanedStack.length > 1) {
276
319
  // Check if this DetailedError was created by Logger.error - look for the frame after Logger.error
277
- const loggerErrorIndex = cleanedStack.findIndex(frame =>
278
- (frame.includes('Logger.error') && frame.includes('logger/Logger.js')) ||
279
- (frame.includes('error@') && frame.includes('logger/Logger.js'))
320
+ const loggerErrorIndex = cleanedStack.findIndex(
321
+ (frame) =>
322
+ (frame.includes('Logger.error') &&
323
+ frame.includes('logger/Logger.js')) ||
324
+ (frame.includes('error@') && frame.includes('logger/Logger.js'))
280
325
  );
281
326
  if (loggerErrorIndex >= 0 && loggerErrorIndex + 1 < cleanedStack.length) {
282
327
  return parseFunctionName(cleanedStack[loggerErrorIndex + 1]);
283
328
  }
284
-
329
+
285
330
  // For rethrow errors, look for the frame after rethrow (handle both formats)
286
- const rethrowIndex = cleanedStack.findIndex(frame =>
287
- frame.includes('rethrow@') || frame.includes('at rethrow (')
331
+ const rethrowIndex = cleanedStack.findIndex(
332
+ (frame) => frame.includes('rethrow@') || frame.includes('at rethrow (')
288
333
  );
289
334
  if (rethrowIndex >= 0 && rethrowIndex + 1 < cleanedStack.length) {
290
335
  return parseFunctionName(cleanedStack[rethrowIndex + 1]);
@@ -293,12 +338,13 @@ export function extractUserFunctionName(error, cleanedStack) {
293
338
 
294
339
  if (error.name === 'PromiseError' && cleanedStack.length > 1) {
295
340
  // For PromiseError, look for the frame after HkPromise methods
296
- const hkPromiseIndex = cleanedStack.findIndex(frame =>
297
- frame.includes('reject@') ||
298
- frame.includes('tryReject@') ||
299
- frame.includes('setTimeout@') ||
300
- frame.includes('cancel@') ||
301
- frame.includes('tryCancel@')
341
+ const hkPromiseIndex = cleanedStack.findIndex(
342
+ (frame) =>
343
+ frame.includes('reject@') ||
344
+ frame.includes('tryReject@') ||
345
+ frame.includes('setTimeout@') ||
346
+ frame.includes('cancel@') ||
347
+ frame.includes('tryCancel@')
302
348
  );
303
349
  if (hkPromiseIndex >= 0 && hkPromiseIndex + 1 < cleanedStack.length) {
304
350
  return parseFunctionName(cleanedStack[hkPromiseIndex + 1]);
@@ -320,15 +366,17 @@ export function extractUserFunctionName(error, cleanedStack) {
320
366
 
321
367
  if (error.name === 'ValiError' && cleanedStack.length > 1) {
322
368
  // For validation errors, look for the frame after expect_ function first (handle Node.js format)
323
- const expectIndex = cleanedStack.findIndex(frame =>
324
- frame.includes('expect_') || frame.includes('Module.expect_')
369
+ const expectIndex = cleanedStack.findIndex(
370
+ (frame) => frame.includes('expect_') || frame.includes('Module.expect_')
325
371
  );
326
372
  if (expectIndex >= 0 && expectIndex + 1 < cleanedStack.length) {
327
373
  return parseFunctionName(cleanedStack[expectIndex + 1]);
328
374
  }
329
-
375
+
330
376
  // If no expect_ function, look for valibotParser wrapper
331
- const valibotIndex = cleanedStack.findIndex(frame => frame.includes('valibotParser'));
377
+ const valibotIndex = cleanedStack.findIndex((frame) =>
378
+ frame.includes('valibotParser')
379
+ );
332
380
  if (valibotIndex >= 0 && valibotIndex + 1 < cleanedStack.length) {
333
381
  return parseFunctionName(cleanedStack[valibotIndex + 1]);
334
382
  }
@@ -347,49 +395,51 @@ export function extractUserFunctionName(error, cleanedStack) {
347
395
 
348
396
  /**
349
397
  * Check if function name is meaningful (not anonymous or framework code)
350
- *
398
+ *
351
399
  * @param {string} functionName - Function name to check
352
400
  * @returns {boolean} True if the function name is meaningful
353
401
  */
354
402
  export function isMeaningfulFunctionName(functionName) {
355
403
  // Skip empty names, anonymous functions, and framework/internal functions
356
- if (!functionName ||
357
- functionName === '' ||
358
- functionName.includes('<') ||
359
- functionName.includes('/') ||
360
- functionName.startsWith('async ') ||
361
- functionName === 'async' ||
362
- functionName === 'Promise' ||
363
- functionName === 'new Promise' ||
364
- functionName.includes('internal') ||
365
- functionName.includes('node_modules')) {
404
+ if (
405
+ !functionName ||
406
+ functionName === '' ||
407
+ functionName.includes('<') ||
408
+ functionName.includes('/') ||
409
+ functionName.startsWith('async ') ||
410
+ functionName === 'async' ||
411
+ functionName === 'Promise' ||
412
+ functionName === 'new Promise' ||
413
+ functionName.includes('internal') ||
414
+ functionName.includes('node_modules')
415
+ ) {
366
416
  return false;
367
417
  }
368
-
418
+
369
419
  return true;
370
420
  }
371
421
 
372
422
  /**
373
423
  * Parse function name from stack frame
374
- *
424
+ *
375
425
  * @param {string} frame - Stack trace frame
376
426
  * @returns {string|null} Function name or null
377
427
  */
378
428
  export function parseFunctionName(frame) {
379
429
  // Handle both Firefox format: "functionName@file:line:col"
380
430
  // and Node.js format: "at functionName (file:line:col)" or "at Module.functionName (file:line:col)"
381
-
431
+
382
432
  // Firefox format
383
433
  const firefoxMatch = frame.match(/^([^@]+)@/);
384
434
  if (firefoxMatch) {
385
435
  return firefoxMatch[1];
386
436
  }
387
-
437
+
388
438
  // Node.js format
389
439
  const nodeMatch = frame.match(/^\s*at\s+(?:Module\.)?([^\s(]+)/);
390
440
  if (nodeMatch) {
391
441
  return nodeMatch[1];
392
442
  }
393
-
443
+
394
444
  return null;
395
- }
445
+ }
@@ -209,9 +209,12 @@ export class PinoAdapter {
209
209
  const pnpmRegex2 = /node_modules\/\.pnpm\/[^/]+\/node_modules\/([^/]+)/g;
210
210
  cleaned = cleaned.replace(pnpmRegex2, 'node_modules/$1');
211
211
 
212
- // Filter out Node.js internal modules
212
+ // Filter out Node.js internal modules and internal logger methods
213
213
  const lines = cleaned.split('\n');
214
- const filteredLines = lines.filter(line => !line.includes('node:internal'));
214
+ const filteredLines = lines.filter(line =>
215
+ !line.includes('node:internal') &&
216
+ !(line.includes('#toError') && line.includes('logger/Logger.js'))
217
+ );
215
218
  cleaned = filteredLines.join('\n');
216
219
 
217
220
  return cleaned;
@@ -57,6 +57,7 @@ import { exportNotNullish } from '../../../util/object.js';
57
57
  // } from './util.js';
58
58
 
59
59
  import * as is from '../../../util/is.js';
60
+ import { HttpError } from '../../../network/errors.js';
60
61
 
61
62
  /**
62
63
  * Logger class for consistent logging
@@ -308,7 +309,8 @@ export default class Logger extends EventEmitter {
308
309
  return (
309
310
  thing instanceof Error ||
310
311
  is.ErrorEvent(thing) ||
311
- is.PromiseRejectionEvent(thing)
312
+ is.PromiseRejectionEvent(thing) ||
313
+ is.SveltekitHttpError(thing)
312
314
  );
313
315
  }
314
316
 
@@ -365,6 +367,18 @@ export default class Logger extends EventEmitter {
365
367
  // reason is not an Error or string
366
368
  return new DetailedError('Promise rejected', reason);
367
369
  }
370
+ } else if (is.SveltekitHttpError(errorLike)) {
371
+ // errorLike is a SvelteKit HttpError
372
+ // => convert to lib's HttpError for consistent error handling
373
+ const svelteKitError = errorLike;
374
+
375
+ return new HttpError(
376
+ svelteKitError.status,
377
+ svelteKitError.body?.message || 'SvelteKit HttpError',
378
+ exportNotNullish(svelteKitError),
379
+ svelteKitError // Set original SvelteKit error as cause
380
+ );
381
+
368
382
  } else if (errorLike instanceof Error) {
369
383
  // errorLike is a plain Error
370
384
  // => return it
@@ -33,3 +33,7 @@ export function throwRethrowChainError(): void;
33
33
  * Raw valibot validation error (without expect wrapper)
34
34
  */
35
35
  export function throwRawValibotError(): any;
36
+ /**
37
+ * SvelteKit error that goes through handleError hook
38
+ */
39
+ export function throwSvelteKitError(): void;
@@ -3,6 +3,7 @@ import { rethrow } from '../../util/exceptions.js';
3
3
  import { HkPromise } from '../../generic/promises.js';
4
4
  import { httpGet } from '../../network/http/index.js';
5
5
  import { v } from '../../valibot/valibot.js';
6
+ import { error } from '@sveltejs/kit';
6
7
 
7
8
  /**
8
9
  * Test functions for generating various types of errors for logging demonstration
@@ -137,3 +138,10 @@ export function throwRawValibotError() {
137
138
  // This will throw a ValiError directly from our valibotParser wrapper
138
139
  return v.parse(schema, invalidValue);
139
140
  }
141
+
142
+ /**
143
+ * SvelteKit error that goes through handleError hook
144
+ */
145
+ export function throwSvelteKitError() {
146
+ throw error(500, 'SvelteKit error test - this goes through handleError');
147
+ }
@@ -81,15 +81,22 @@ export default class ConfigPlugin {
81
81
  */
82
82
  // eslint-disable-next-line no-unused-vars
83
83
  async resolveServiceConfig(serviceName, serviceEntry, currentConfig) {
84
+ // console.log(`ConfigPlugin.resolveServiceConfig called for '${serviceName}'`);
85
+ // console.log('ServiceEntry:', serviceEntry);
86
+ // console.log('AllConfigs:', this.allConfigs);
87
+
84
88
  const configLabel = serviceEntry.serviceConfigOrLabel;
89
+ // console.log('Config label:', configLabel, 'Type:', typeof configLabel);
85
90
 
86
91
  if (typeof configLabel !== 'string') {
92
+ // console.log('Config label is not string, returning undefined');
87
93
  // Expected config label
88
94
  return undefined;
89
95
  }
90
96
 
91
97
  // Simple object lookup
92
98
  const config = this.allConfigs[configLabel];
99
+ // console.log(`Looking up config for label '${configLabel}':`, config);
93
100
 
94
101
  if (config !== undefined) {
95
102
  this.manager?.logger?.debug(
@@ -99,6 +106,9 @@ export default class ConfigPlugin {
99
106
  typeof config === 'object' ? Object.keys(config) : 'primitive'
100
107
  }
101
108
  );
109
+ // console.log(`Resolved config for '${serviceName}':`, config);
110
+ } else {
111
+ // console.log(`No config found for label '${configLabel}'`);
102
112
  }
103
113
 
104
114
  return config;
@@ -174,7 +174,7 @@ export class ServiceManager extends EventEmitter {
174
174
  const entry = {
175
175
  ServiceClass,
176
176
  instance: null,
177
- serviceConfigOrLabel,
177
+ serviceConfigOrLabel: serviceConfigOrLabel,
178
178
  dependencies: options.dependencies || [],
179
179
  dependents: new Set(),
180
180
  tags: options.tags || [],
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Check if object is a SvelteKit HttpError
3
+ *
4
+ * @param {any} thing
5
+ *
6
+ * @returns {boolean}
7
+ */
8
+ export function SveltekitHttpError(thing: any): boolean;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Check if object is a SvelteKit HttpError
3
+ *
4
+ * @param {any} thing
5
+ *
6
+ * @returns {boolean}
7
+ */
8
+ export function SveltekitHttpError(thing) {
9
+ return Boolean(
10
+ thing instanceof Object &&
11
+ thing.constructor?.name === 'HttpError' &&
12
+ 'status' in thing
13
+ );
14
+ }
package/dist/util/is.d.ts CHANGED
@@ -1 +1,3 @@
1
+ export * from "./is/events.js";
1
2
  export * from "./is/index.js";
3
+ export * from "./is/sveltekit.js";
package/dist/util/is.js CHANGED
@@ -5,4 +5,6 @@
5
5
  * This module provides type checking and validation utilities.
6
6
  */
7
7
 
8
- export * from './is/index.js';
8
+ export * from './is/events.js';
9
+ export * from './is/index.js';
10
+ export * from './is/sveltekit.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.4.20",
3
+ "version": "0.4.22",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"