( errorsBudget= defaultLoggedErrorsBudget, argsPerErrorBudget= defaultArgsPerErrorBudget)
| 1373 | * @param {number} [argsPerErrorBudget] |
| 1374 | */ |
| 1375 | const makeNoteLogArgsArrayKit= ( |
| 1376 | errorsBudget= defaultLoggedErrorsBudget, |
| 1377 | argsPerErrorBudget= defaultArgsPerErrorBudget)=> |
| 1378 | { |
| 1379 | if( !isSafeInteger(argsPerErrorBudget)|| argsPerErrorBudget< 1) { |
| 1380 | throw TypeError( |
| 1381 | 'argsPerErrorBudget must be a safe positive integer number'); |
| 1382 | |
| 1383 | } |
| 1384 | |
| 1385 | /** |
| 1386 | * @type {WeakMap<Error, LogArgs[]>} |
| 1387 | * |
| 1388 | * Maps from an error to an array of log args, where each log args is |
| 1389 | * remembered as an annotation on that error. This can be used, for example, |
| 1390 | * to keep track of additional causes of the error. The elements of any |
| 1391 | * log args may include errors which are associated with further annotations. |
| 1392 | * An augmented console, like the causal console of `console.js`, could |
| 1393 | * then retrieve the graph of such annotations. |
| 1394 | */ |
| 1395 | const noteLogArgsArrayMap= makeLRUCacheMap(errorsBudget); |
| 1396 | |
| 1397 | /** |
| 1398 | * @param {Error} error |
| 1399 | * @param {LogArgs} logArgs |
| 1400 | */ |
| 1401 | const addLogArgs= (error, logArgs)=> { |
| 1402 | const logArgsArray= noteLogArgsArrayMap.get(error); |
| 1403 | if( logArgsArray!== undefined) { |
| 1404 | if( logArgsArray.length>= argsPerErrorBudget) { |
| 1405 | logArgsArray.shift(); |
| 1406 | } |
| 1407 | logArgsArray.push(logArgs); |
| 1408 | }else { |
| 1409 | noteLogArgsArrayMap.set(error, [logArgs]); |
| 1410 | } |
| 1411 | }; |
| 1412 | freeze(addLogArgs); |
| 1413 | |
| 1414 | /** |
| 1415 | * @param {Error} error |
| 1416 | * @returns {LogArgs[] | undefined} |
| 1417 | */ |
| 1418 | const takeLogArgsArray= (error)=>{ |
| 1419 | const result= noteLogArgsArrayMap.get(error); |
| 1420 | noteLogArgsArrayMap.delete(error); |
| 1421 | return result; |
| 1422 | }; |
| 1423 | freeze(takeLogArgsArray); |
| 1424 | |
| 1425 | return freeze({ |
| 1426 | addLogArgs, |
| 1427 | takeLogArgsArray}); |
| 1428 | |
| 1429 | };$h_once.makeNoteLogArgsArrayKit(makeNoteLogArgsArrayKit); |
| 1430 | freeze(makeNoteLogArgsArrayKit); |
| 1431 | })() |
| 1432 | , |
no test coverage detected