@spfn/core 0.1.0-alpha.68 → 0.1.0-alpha.72
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.
- package/dist/client/index.d.ts +2 -1
- package/dist/codegen/generators/index.js +59 -57
- package/dist/codegen/generators/index.js.map +1 -1
- package/dist/codegen/index.d.ts +2 -1
- package/dist/codegen/index.js +59 -57
- package/dist/codegen/index.js.map +1 -1
- package/dist/{database-errors-CoPrcOpq.d.ts → database-errors-BNNmLTJE.d.ts} +4 -4
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js.map +1 -1
- package/dist/errors/index.d.ts +20 -3
- package/dist/errors/index.js +15 -3
- package/dist/errors/index.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +115 -109
- package/dist/index.js.map +1 -1
- package/dist/route/index.d.ts +5 -157
- package/dist/route/index.js +86 -96
- package/dist/route/index.js.map +1 -1
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +115 -109
- package/dist/server/index.js.map +1 -1
- package/dist/types-Dzggq1Yb.d.ts +170 -0
- package/package.json +1 -1
- package/dist/types-CAON3Mmg.d.ts +0 -57
package/dist/index.js
CHANGED
|
@@ -128,11 +128,11 @@ function formatTimestampHuman(date) {
|
|
|
128
128
|
const ms = String(date.getMilliseconds()).padStart(3, "0");
|
|
129
129
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${ms}`;
|
|
130
130
|
}
|
|
131
|
-
function formatError(
|
|
131
|
+
function formatError(error) {
|
|
132
132
|
const lines = [];
|
|
133
|
-
lines.push(`${
|
|
134
|
-
if (
|
|
135
|
-
const stackLines =
|
|
133
|
+
lines.push(`${error.name}: ${error.message}`);
|
|
134
|
+
if (error.stack) {
|
|
135
|
+
const stackLines = error.stack.split("\n").slice(1);
|
|
136
136
|
lines.push(...stackLines);
|
|
137
137
|
}
|
|
138
138
|
return lines.join("\n");
|
|
@@ -318,7 +318,7 @@ var init_logger = __esm({
|
|
|
318
318
|
/**
|
|
319
319
|
* Log processing (internal)
|
|
320
320
|
*/
|
|
321
|
-
log(level, message,
|
|
321
|
+
log(level, message, error, context) {
|
|
322
322
|
if (LOG_LEVEL_PRIORITY[level] < LOG_LEVEL_PRIORITY[this.config.level]) {
|
|
323
323
|
return;
|
|
324
324
|
}
|
|
@@ -327,7 +327,7 @@ var init_logger = __esm({
|
|
|
327
327
|
level,
|
|
328
328
|
message,
|
|
329
329
|
module: this.module,
|
|
330
|
-
error
|
|
330
|
+
error,
|
|
331
331
|
// Mask sensitive information in context to prevent credential leaks
|
|
332
332
|
context: context ? maskSensitiveData(context) : void 0
|
|
333
333
|
};
|
|
@@ -338,8 +338,8 @@ var init_logger = __esm({
|
|
|
338
338
|
*/
|
|
339
339
|
processTransports(metadata) {
|
|
340
340
|
const promises = this.config.transports.filter((transport) => transport.enabled).map((transport) => this.safeTransportLog(transport, metadata));
|
|
341
|
-
Promise.all(promises).catch((
|
|
342
|
-
const errorMessage =
|
|
341
|
+
Promise.all(promises).catch((error) => {
|
|
342
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
343
343
|
process.stderr.write(`[Logger] Transport error: ${errorMessage}
|
|
344
344
|
`);
|
|
345
345
|
});
|
|
@@ -350,8 +350,8 @@ var init_logger = __esm({
|
|
|
350
350
|
async safeTransportLog(transport, metadata) {
|
|
351
351
|
try {
|
|
352
352
|
await transport.log(metadata);
|
|
353
|
-
} catch (
|
|
354
|
-
const errorMessage =
|
|
353
|
+
} catch (error) {
|
|
354
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
355
355
|
process.stderr.write(`[Logger] Transport "${transport.name}" failed: ${errorMessage}
|
|
356
356
|
`);
|
|
357
357
|
}
|
|
@@ -441,11 +441,11 @@ var init_file = __esm({
|
|
|
441
441
|
}
|
|
442
442
|
if (this.currentStream) {
|
|
443
443
|
return new Promise((resolve, reject) => {
|
|
444
|
-
this.currentStream.write(message + "\n", "utf-8", (
|
|
445
|
-
if (
|
|
446
|
-
process.stderr.write(`[FileTransport] Failed to write log: ${
|
|
444
|
+
this.currentStream.write(message + "\n", "utf-8", (error) => {
|
|
445
|
+
if (error) {
|
|
446
|
+
process.stderr.write(`[FileTransport] Failed to write log: ${error.message}
|
|
447
447
|
`);
|
|
448
|
-
reject(
|
|
448
|
+
reject(error);
|
|
449
449
|
} else {
|
|
450
450
|
resolve();
|
|
451
451
|
}
|
|
@@ -467,8 +467,8 @@ var init_file = __esm({
|
|
|
467
467
|
encoding: "utf-8"
|
|
468
468
|
});
|
|
469
469
|
this.currentFilename = filename;
|
|
470
|
-
this.currentStream.on("error", (
|
|
471
|
-
process.stderr.write(`[FileTransport] Stream error: ${
|
|
470
|
+
this.currentStream.on("error", (error) => {
|
|
471
|
+
process.stderr.write(`[FileTransport] Stream error: ${error.message}
|
|
472
472
|
`);
|
|
473
473
|
this.currentStream = null;
|
|
474
474
|
this.currentFilename = null;
|
|
@@ -482,9 +482,9 @@ var init_file = __esm({
|
|
|
482
482
|
return;
|
|
483
483
|
}
|
|
484
484
|
return new Promise((resolve, reject) => {
|
|
485
|
-
this.currentStream.end((
|
|
486
|
-
if (
|
|
487
|
-
reject(
|
|
485
|
+
this.currentStream.end((error) => {
|
|
486
|
+
if (error) {
|
|
487
|
+
reject(error);
|
|
488
488
|
} else {
|
|
489
489
|
this.currentStream = null;
|
|
490
490
|
this.currentFilename = null;
|
|
@@ -509,8 +509,8 @@ var init_file = __esm({
|
|
|
509
509
|
if (stats.size >= this.maxFileSize) {
|
|
510
510
|
await this.rotateBySize();
|
|
511
511
|
}
|
|
512
|
-
} catch (
|
|
513
|
-
const errorMessage =
|
|
512
|
+
} catch (error) {
|
|
513
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
514
514
|
process.stderr.write(`[FileTransport] Failed to check file size: ${errorMessage}
|
|
515
515
|
`);
|
|
516
516
|
}
|
|
@@ -536,8 +536,8 @@ var init_file = __esm({
|
|
|
536
536
|
const newPath2 = join(this.logDir, `${baseName}.${newNum}.log`);
|
|
537
537
|
try {
|
|
538
538
|
renameSync(oldPath, newPath2);
|
|
539
|
-
} catch (
|
|
540
|
-
const errorMessage =
|
|
539
|
+
} catch (error) {
|
|
540
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
541
541
|
process.stderr.write(`[FileTransport] Failed to rotate file: ${errorMessage}
|
|
542
542
|
`);
|
|
543
543
|
}
|
|
@@ -549,8 +549,8 @@ var init_file = __esm({
|
|
|
549
549
|
if (existsSync(currentPath)) {
|
|
550
550
|
renameSync(currentPath, newPath);
|
|
551
551
|
}
|
|
552
|
-
} catch (
|
|
553
|
-
const errorMessage =
|
|
552
|
+
} catch (error) {
|
|
553
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
554
554
|
process.stderr.write(`[FileTransport] Failed to rotate current file: ${errorMessage}
|
|
555
555
|
`);
|
|
556
556
|
}
|
|
@@ -577,15 +577,15 @@ var init_file = __esm({
|
|
|
577
577
|
const filepath = join(this.logDir, file);
|
|
578
578
|
try {
|
|
579
579
|
unlinkSync(filepath);
|
|
580
|
-
} catch (
|
|
581
|
-
const errorMessage =
|
|
580
|
+
} catch (error) {
|
|
581
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
582
582
|
process.stderr.write(`[FileTransport] Failed to delete old file "${file}": ${errorMessage}
|
|
583
583
|
`);
|
|
584
584
|
}
|
|
585
585
|
}
|
|
586
586
|
}
|
|
587
|
-
} catch (
|
|
588
|
-
const errorMessage =
|
|
587
|
+
} catch (error) {
|
|
588
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
589
589
|
process.stderr.write(`[FileTransport] Failed to clean old files: ${errorMessage}
|
|
590
590
|
`);
|
|
591
591
|
}
|
|
@@ -644,8 +644,8 @@ function validateDirectoryWritable(dirPath) {
|
|
|
644
644
|
if (!existsSync(dirPath)) {
|
|
645
645
|
try {
|
|
646
646
|
mkdirSync(dirPath, { recursive: true });
|
|
647
|
-
} catch (
|
|
648
|
-
const errorMessage =
|
|
647
|
+
} catch (error) {
|
|
648
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
649
649
|
throw new Error(`Failed to create log directory "${dirPath}": ${errorMessage}`);
|
|
650
650
|
}
|
|
651
651
|
}
|
|
@@ -658,8 +658,8 @@ function validateDirectoryWritable(dirPath) {
|
|
|
658
658
|
try {
|
|
659
659
|
writeFileSync(testFile, "test", "utf-8");
|
|
660
660
|
unlinkSync(testFile);
|
|
661
|
-
} catch (
|
|
662
|
-
const errorMessage =
|
|
661
|
+
} catch (error) {
|
|
662
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
663
663
|
throw new Error(`Cannot write to log directory "${dirPath}": ${errorMessage}`);
|
|
664
664
|
}
|
|
665
665
|
}
|
|
@@ -736,11 +736,11 @@ function validateConfig() {
|
|
|
736
736
|
validateFileConfig();
|
|
737
737
|
validateSlackConfig();
|
|
738
738
|
validateEmailConfig();
|
|
739
|
-
} catch (
|
|
740
|
-
if (
|
|
741
|
-
throw new Error(`[Logger] Configuration validation failed: ${
|
|
739
|
+
} catch (error) {
|
|
740
|
+
if (error instanceof Error) {
|
|
741
|
+
throw new Error(`[Logger] Configuration validation failed: ${error.message}`);
|
|
742
742
|
}
|
|
743
|
-
throw
|
|
743
|
+
throw error;
|
|
744
744
|
}
|
|
745
745
|
}
|
|
746
746
|
var init_config = __esm({
|
|
@@ -894,12 +894,12 @@ function discoverFunctionRoutes(cwd = process.cwd()) {
|
|
|
894
894
|
prefix: prefix || "(none)"
|
|
895
895
|
});
|
|
896
896
|
}
|
|
897
|
-
} catch (
|
|
897
|
+
} catch (error) {
|
|
898
898
|
}
|
|
899
899
|
}
|
|
900
|
-
} catch (
|
|
900
|
+
} catch (error) {
|
|
901
901
|
routeLogger.warn("Failed to discover function routes", {
|
|
902
|
-
error:
|
|
902
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
903
903
|
});
|
|
904
904
|
}
|
|
905
905
|
return functions;
|
|
@@ -1076,8 +1076,8 @@ function loadSingleFile(filePath, debug) {
|
|
|
1076
1076
|
});
|
|
1077
1077
|
}
|
|
1078
1078
|
return { success: true, parsed };
|
|
1079
|
-
} catch (
|
|
1080
|
-
const message =
|
|
1079
|
+
} catch (error) {
|
|
1080
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
1081
1081
|
envLogger.error("Error loading environment file", {
|
|
1082
1082
|
path: filePath,
|
|
1083
1083
|
error: message
|
|
@@ -1093,12 +1093,12 @@ function validateRequiredVars(required, debug) {
|
|
|
1093
1093
|
}
|
|
1094
1094
|
}
|
|
1095
1095
|
if (missing.length > 0) {
|
|
1096
|
-
const
|
|
1096
|
+
const error = `Required environment variables missing: ${missing.join(", ")}`;
|
|
1097
1097
|
envLogger.error("Environment validation failed", {
|
|
1098
1098
|
missing,
|
|
1099
1099
|
required
|
|
1100
1100
|
});
|
|
1101
|
-
throw new Error(
|
|
1101
|
+
throw new Error(error);
|
|
1102
1102
|
}
|
|
1103
1103
|
if (debug) {
|
|
1104
1104
|
envLogger.debug("Required environment variables validated", {
|
|
@@ -1179,12 +1179,12 @@ function loadEnvironment(options = {}) {
|
|
|
1179
1179
|
if (required.length > 0) {
|
|
1180
1180
|
try {
|
|
1181
1181
|
validateRequiredVars(required, debug);
|
|
1182
|
-
} catch (
|
|
1182
|
+
} catch (error) {
|
|
1183
1183
|
result.success = false;
|
|
1184
1184
|
result.errors = [
|
|
1185
|
-
|
|
1185
|
+
error instanceof Error ? error.message : "Validation failed"
|
|
1186
1186
|
];
|
|
1187
|
-
throw
|
|
1187
|
+
throw error;
|
|
1188
1188
|
}
|
|
1189
1189
|
}
|
|
1190
1190
|
if (result.warnings.length > 0) {
|
|
@@ -1241,9 +1241,9 @@ function parseUniqueViolation(message) {
|
|
|
1241
1241
|
}
|
|
1242
1242
|
return null;
|
|
1243
1243
|
}
|
|
1244
|
-
function fromPostgresError(
|
|
1245
|
-
const code =
|
|
1246
|
-
const message =
|
|
1244
|
+
function fromPostgresError(error) {
|
|
1245
|
+
const code = error?.code;
|
|
1246
|
+
const message = error?.message || "Database error occurred";
|
|
1247
1247
|
switch (code) {
|
|
1248
1248
|
// Class 08 — Connection Exception
|
|
1249
1249
|
case "08000":
|
|
@@ -1359,8 +1359,8 @@ async function createDatabaseConnection(connectionString, poolConfig, retryConfi
|
|
|
1359
1359
|
dbLogger.info("Database connected successfully");
|
|
1360
1360
|
}
|
|
1361
1361
|
return client;
|
|
1362
|
-
} catch (
|
|
1363
|
-
lastError = fromPostgresError(
|
|
1362
|
+
} catch (error) {
|
|
1363
|
+
lastError = fromPostgresError(error);
|
|
1364
1364
|
if (attempt < retryConfig.maxRetries) {
|
|
1365
1365
|
const delayMs = Math.min(
|
|
1366
1366
|
retryConfig.initialDelay * Math.pow(retryConfig.factor, attempt),
|
|
@@ -1386,8 +1386,8 @@ async function checkConnection(client) {
|
|
|
1386
1386
|
try {
|
|
1387
1387
|
await client`SELECT 1 as health_check`;
|
|
1388
1388
|
return true;
|
|
1389
|
-
} catch (
|
|
1390
|
-
dbLogger.error("Database health check failed",
|
|
1389
|
+
} catch (error) {
|
|
1390
|
+
dbLogger.error("Database health check failed", error);
|
|
1391
1391
|
return false;
|
|
1392
1392
|
}
|
|
1393
1393
|
}
|
|
@@ -1557,8 +1557,8 @@ async function createDatabaseFromEnv(options) {
|
|
|
1557
1557
|
dbLogger2.warn("No database pattern detected");
|
|
1558
1558
|
return { write: void 0, read: void 0 };
|
|
1559
1559
|
}
|
|
1560
|
-
} catch (
|
|
1561
|
-
const message =
|
|
1560
|
+
} catch (error) {
|
|
1561
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
1562
1562
|
dbLogger2.error("Failed to create database connection", {
|
|
1563
1563
|
error: message,
|
|
1564
1564
|
stage: "initialization",
|
|
@@ -1567,7 +1567,7 @@ async function createDatabaseFromEnv(options) {
|
|
|
1567
1567
|
hasUrl: !!process.env.DATABASE_URL,
|
|
1568
1568
|
hasReplicaUrl: !!process.env.DATABASE_REPLICA_URL
|
|
1569
1569
|
});
|
|
1570
|
-
throw new Error(`Database connection failed: ${message}`, { cause:
|
|
1570
|
+
throw new Error(`Database connection failed: ${message}`, { cause: error });
|
|
1571
1571
|
}
|
|
1572
1572
|
}
|
|
1573
1573
|
var dbLogger2;
|
|
@@ -1632,8 +1632,8 @@ function startHealthCheck(config, options, getDatabase2, closeDatabase2) {
|
|
|
1632
1632
|
if (read && read !== write) {
|
|
1633
1633
|
await read.execute("SELECT 1");
|
|
1634
1634
|
}
|
|
1635
|
-
} catch (
|
|
1636
|
-
const message =
|
|
1635
|
+
} catch (error) {
|
|
1636
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
1637
1637
|
dbLogger3.error("Database health check failed", { error: message });
|
|
1638
1638
|
if (config.reconnect) {
|
|
1639
1639
|
await attemptReconnection(config, options, closeDatabase2);
|
|
@@ -1662,8 +1662,8 @@ async function attemptReconnection(config, options, closeDatabase2) {
|
|
|
1662
1662
|
dbLogger3.info("Database reconnection successful", { attempt });
|
|
1663
1663
|
return;
|
|
1664
1664
|
}
|
|
1665
|
-
} catch (
|
|
1666
|
-
const message =
|
|
1665
|
+
} catch (error) {
|
|
1666
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
1667
1667
|
dbLogger3.error(`Reconnection attempt ${attempt} failed`, {
|
|
1668
1668
|
error: message,
|
|
1669
1669
|
attempt,
|
|
@@ -1740,11 +1740,11 @@ async function initDatabase(options) {
|
|
|
1740
1740
|
logQueries: monConfig.logQueries
|
|
1741
1741
|
});
|
|
1742
1742
|
}
|
|
1743
|
-
} catch (
|
|
1744
|
-
const message =
|
|
1743
|
+
} catch (error) {
|
|
1744
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
1745
1745
|
dbLogger4.error("Database connection failed", { error: message });
|
|
1746
1746
|
await closeDatabase();
|
|
1747
|
-
throw new Error(`Database connection test failed: ${message}`, { cause:
|
|
1747
|
+
throw new Error(`Database connection test failed: ${message}`, { cause: error });
|
|
1748
1748
|
}
|
|
1749
1749
|
} else {
|
|
1750
1750
|
dbLogger4.warn("No database configuration found");
|
|
@@ -1778,9 +1778,9 @@ async function closeDatabase() {
|
|
|
1778
1778
|
}
|
|
1779
1779
|
await Promise.all(closePromises);
|
|
1780
1780
|
dbLogger4.info("All database connections closed");
|
|
1781
|
-
} catch (
|
|
1782
|
-
dbLogger4.error("Error during database cleanup",
|
|
1783
|
-
throw
|
|
1781
|
+
} catch (error) {
|
|
1782
|
+
dbLogger4.error("Error during database cleanup", error);
|
|
1783
|
+
throw error;
|
|
1784
1784
|
} finally {
|
|
1785
1785
|
setWriteInstance(void 0);
|
|
1786
1786
|
setReadInstance(void 0);
|
|
@@ -1886,7 +1886,7 @@ function discoverPackageSchemas(cwd) {
|
|
|
1886
1886
|
...Object.keys(projectPkg.dependencies || {}),
|
|
1887
1887
|
...Object.keys(projectPkg.devDependencies || {})
|
|
1888
1888
|
]);
|
|
1889
|
-
} catch (
|
|
1889
|
+
} catch (error) {
|
|
1890
1890
|
}
|
|
1891
1891
|
}
|
|
1892
1892
|
const checkPackage = (_pkgName, pkgPath) => {
|
|
@@ -1905,7 +1905,7 @@ function discoverPackageSchemas(cwd) {
|
|
|
1905
1905
|
schemas.push(...schemaFiles);
|
|
1906
1906
|
}
|
|
1907
1907
|
}
|
|
1908
|
-
} catch (
|
|
1908
|
+
} catch (error) {
|
|
1909
1909
|
}
|
|
1910
1910
|
};
|
|
1911
1911
|
const spfnDir = join(nodeModulesPath, "@spfn");
|
|
@@ -1915,7 +1915,7 @@ function discoverPackageSchemas(cwd) {
|
|
|
1915
1915
|
for (const pkg of spfnPackages) {
|
|
1916
1916
|
checkPackage(`@spfn/${pkg}`, join(spfnDir, pkg));
|
|
1917
1917
|
}
|
|
1918
|
-
} catch (
|
|
1918
|
+
} catch (error) {
|
|
1919
1919
|
}
|
|
1920
1920
|
}
|
|
1921
1921
|
for (const depName of directDeps) {
|
|
@@ -2159,9 +2159,9 @@ function Transactional(options = {}) {
|
|
|
2159
2159
|
});
|
|
2160
2160
|
}
|
|
2161
2161
|
}
|
|
2162
|
-
} catch (
|
|
2162
|
+
} catch (error) {
|
|
2163
2163
|
const duration = Date.now() - startTime;
|
|
2164
|
-
const customError =
|
|
2164
|
+
const customError = error instanceof TransactionError ? error : fromPostgresError(error);
|
|
2165
2165
|
if (enableLogging) {
|
|
2166
2166
|
txLogger2.error("Transaction rolled back", {
|
|
2167
2167
|
txId,
|
|
@@ -2467,12 +2467,12 @@ async function createCacheFromEnv() {
|
|
|
2467
2467
|
}
|
|
2468
2468
|
cacheLogger.info("No valid cache configuration found - running without cache");
|
|
2469
2469
|
return { write: void 0, read: void 0 };
|
|
2470
|
-
} catch (
|
|
2471
|
-
if (
|
|
2472
|
-
if (
|
|
2470
|
+
} catch (error) {
|
|
2471
|
+
if (error instanceof Error) {
|
|
2472
|
+
if (error.message.includes("Cannot find module")) {
|
|
2473
2473
|
cacheLogger.warn(
|
|
2474
2474
|
"Cache client library not installed",
|
|
2475
|
-
|
|
2475
|
+
error,
|
|
2476
2476
|
{
|
|
2477
2477
|
suggestion: "Install ioredis to enable cache: pnpm install ioredis",
|
|
2478
2478
|
mode: "disabled"
|
|
@@ -2481,14 +2481,14 @@ async function createCacheFromEnv() {
|
|
|
2481
2481
|
} else {
|
|
2482
2482
|
cacheLogger.warn(
|
|
2483
2483
|
"Failed to create cache client",
|
|
2484
|
-
|
|
2484
|
+
error,
|
|
2485
2485
|
{ mode: "disabled" }
|
|
2486
2486
|
);
|
|
2487
2487
|
}
|
|
2488
2488
|
} else {
|
|
2489
2489
|
cacheLogger.warn(
|
|
2490
2490
|
"Failed to create cache client",
|
|
2491
|
-
{ error: String(
|
|
2491
|
+
{ error: String(error), mode: "disabled" }
|
|
2492
2492
|
);
|
|
2493
2493
|
}
|
|
2494
2494
|
return { write: void 0, read: void 0 };
|
|
@@ -2541,10 +2541,10 @@ async function initCache() {
|
|
|
2541
2541
|
{ mode: "enabled" }
|
|
2542
2542
|
);
|
|
2543
2543
|
return { write: writeInstance, read: readInstance, disabled: false };
|
|
2544
|
-
} catch (
|
|
2544
|
+
} catch (error) {
|
|
2545
2545
|
cacheLogger2.error(
|
|
2546
2546
|
"Cache connection failed - running in disabled mode",
|
|
2547
|
-
|
|
2547
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
2548
2548
|
{ mode: "disabled" }
|
|
2549
2549
|
);
|
|
2550
2550
|
try {
|
|
@@ -2663,8 +2663,8 @@ var AutoRouteLoader = class {
|
|
|
2663
2663
|
}
|
|
2664
2664
|
let failureCount = 0;
|
|
2665
2665
|
for (const file of files) {
|
|
2666
|
-
const
|
|
2667
|
-
if (
|
|
2666
|
+
const success = await this.loadRoute(app, file);
|
|
2667
|
+
if (success) ; else {
|
|
2668
2668
|
failureCount++;
|
|
2669
2669
|
}
|
|
2670
2670
|
}
|
|
@@ -2701,8 +2701,8 @@ var AutoRouteLoader = class {
|
|
|
2701
2701
|
let successCount = 0;
|
|
2702
2702
|
let failureCount = 0;
|
|
2703
2703
|
for (const file of files) {
|
|
2704
|
-
const
|
|
2705
|
-
if (
|
|
2704
|
+
const success = await this.loadRoute(app, file, prefix);
|
|
2705
|
+
if (success) {
|
|
2706
2706
|
successCount++;
|
|
2707
2707
|
} else {
|
|
2708
2708
|
failureCount++;
|
|
@@ -2800,8 +2800,8 @@ var AutoRouteLoader = class {
|
|
|
2800
2800
|
}
|
|
2801
2801
|
});
|
|
2802
2802
|
return true;
|
|
2803
|
-
} catch (
|
|
2804
|
-
this.categorizeAndLogError(
|
|
2803
|
+
} catch (error) {
|
|
2804
|
+
this.categorizeAndLogError(error, relativePath);
|
|
2805
2805
|
return false;
|
|
2806
2806
|
}
|
|
2807
2807
|
}
|
|
@@ -2857,9 +2857,9 @@ var AutoRouteLoader = class {
|
|
|
2857
2857
|
}
|
|
2858
2858
|
}
|
|
2859
2859
|
}
|
|
2860
|
-
categorizeAndLogError(
|
|
2861
|
-
const message =
|
|
2862
|
-
const stack =
|
|
2860
|
+
categorizeAndLogError(error, relativePath) {
|
|
2861
|
+
const message = error.message;
|
|
2862
|
+
const stack = error.stack;
|
|
2863
2863
|
if (message.includes("Cannot find module") || message.includes("MODULE_NOT_FOUND")) {
|
|
2864
2864
|
routeLogger2.error("Missing dependency", {
|
|
2865
2865
|
file: relativePath,
|
|
@@ -2922,10 +2922,10 @@ async function loadRoutes(app, options) {
|
|
|
2922
2922
|
routesDir: func.routesDir,
|
|
2923
2923
|
prefix: func.prefix || "/"
|
|
2924
2924
|
});
|
|
2925
|
-
} catch (
|
|
2925
|
+
} catch (error) {
|
|
2926
2926
|
routeLogger2.error("Failed to load function routes", {
|
|
2927
2927
|
package: func.packageName,
|
|
2928
|
-
error:
|
|
2928
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
2929
2929
|
});
|
|
2930
2930
|
}
|
|
2931
2931
|
}
|
|
@@ -3027,15 +3027,15 @@ function RequestLogger(config) {
|
|
|
3027
3027
|
logData.slow = true;
|
|
3028
3028
|
}
|
|
3029
3029
|
apiLogger[logLevel]("Request completed", logData);
|
|
3030
|
-
} catch (
|
|
3030
|
+
} catch (error) {
|
|
3031
3031
|
const duration = Date.now() - startTime;
|
|
3032
|
-
apiLogger.error("Request failed",
|
|
3032
|
+
apiLogger.error("Request failed", error, {
|
|
3033
3033
|
requestId,
|
|
3034
3034
|
method,
|
|
3035
3035
|
path,
|
|
3036
3036
|
duration
|
|
3037
3037
|
});
|
|
3038
|
-
throw
|
|
3038
|
+
throw error;
|
|
3039
3039
|
}
|
|
3040
3040
|
};
|
|
3041
3041
|
}
|
|
@@ -3065,9 +3065,9 @@ function createHealthCheckHandler(detailed) {
|
|
|
3065
3065
|
try {
|
|
3066
3066
|
await db.execute("SELECT 1");
|
|
3067
3067
|
dbStatus = "connected";
|
|
3068
|
-
} catch (
|
|
3068
|
+
} catch (error) {
|
|
3069
3069
|
dbStatus = "error";
|
|
3070
|
-
dbError =
|
|
3070
|
+
dbError = error instanceof Error ? error.message : String(error);
|
|
3071
3071
|
}
|
|
3072
3072
|
}
|
|
3073
3073
|
const redis = getRedis2();
|
|
@@ -3077,9 +3077,9 @@ function createHealthCheckHandler(detailed) {
|
|
|
3077
3077
|
try {
|
|
3078
3078
|
await redis.ping();
|
|
3079
3079
|
redisStatus = "connected";
|
|
3080
|
-
} catch (
|
|
3080
|
+
} catch (error) {
|
|
3081
3081
|
redisStatus = "error";
|
|
3082
|
-
redisError =
|
|
3082
|
+
redisError = error instanceof Error ? error.message : String(error);
|
|
3083
3083
|
}
|
|
3084
3084
|
}
|
|
3085
3085
|
response.services = {
|
|
@@ -3192,6 +3192,12 @@ async function createAutoConfiguredApp(config) {
|
|
|
3192
3192
|
const enableLogger = middlewareConfig.logger !== false;
|
|
3193
3193
|
const enableCors = middlewareConfig.cors !== false;
|
|
3194
3194
|
const enableErrorHandler = middlewareConfig.errorHandler !== false;
|
|
3195
|
+
if (enableErrorHandler) {
|
|
3196
|
+
app.use("*", async (c, next) => {
|
|
3197
|
+
c.set("errorHandlerEnabled", true);
|
|
3198
|
+
await next();
|
|
3199
|
+
});
|
|
3200
|
+
}
|
|
3195
3201
|
applyDefaultMiddleware(app, config, enableLogger, enableCors);
|
|
3196
3202
|
config?.use?.forEach((mw) => app.use("*", mw));
|
|
3197
3203
|
registerHealthCheckEndpoint(app, config);
|
|
@@ -3227,8 +3233,8 @@ async function executeBeforeRoutesHook(app, config) {
|
|
|
3227
3233
|
}
|
|
3228
3234
|
try {
|
|
3229
3235
|
await config.beforeRoutes(app);
|
|
3230
|
-
} catch (
|
|
3231
|
-
serverLogger.error("beforeRoutes hook failed",
|
|
3236
|
+
} catch (error) {
|
|
3237
|
+
serverLogger.error("beforeRoutes hook failed", error);
|
|
3232
3238
|
throw new Error("Server initialization failed in beforeRoutes hook");
|
|
3233
3239
|
}
|
|
3234
3240
|
}
|
|
@@ -3246,8 +3252,8 @@ async function executeAfterRoutesHook(app, config) {
|
|
|
3246
3252
|
}
|
|
3247
3253
|
try {
|
|
3248
3254
|
await config.afterRoutes(app);
|
|
3249
|
-
} catch (
|
|
3250
|
-
serverLogger.error("afterRoutes hook failed",
|
|
3255
|
+
} catch (error) {
|
|
3256
|
+
serverLogger.error("afterRoutes hook failed", error);
|
|
3251
3257
|
throw new Error("Server initialization failed in afterRoutes hook");
|
|
3252
3258
|
}
|
|
3253
3259
|
}
|
|
@@ -3367,11 +3373,11 @@ async function startServer(config) {
|
|
|
3367
3373
|
await shutdownServer();
|
|
3368
3374
|
}
|
|
3369
3375
|
};
|
|
3370
|
-
} catch (
|
|
3371
|
-
const err =
|
|
3376
|
+
} catch (error) {
|
|
3377
|
+
const err = error;
|
|
3372
3378
|
serverLogger2.error("Server initialization failed", err);
|
|
3373
3379
|
await cleanupOnFailure();
|
|
3374
|
-
throw
|
|
3380
|
+
throw error;
|
|
3375
3381
|
}
|
|
3376
3382
|
}
|
|
3377
3383
|
async function loadAndMergeConfig(config) {
|
|
@@ -3469,8 +3475,8 @@ function createGracefulShutdown(shutdownServer, config) {
|
|
|
3469
3475
|
]);
|
|
3470
3476
|
serverLogger2.info("Graceful shutdown completed successfully");
|
|
3471
3477
|
process.exit(0);
|
|
3472
|
-
} catch (
|
|
3473
|
-
const err =
|
|
3478
|
+
} catch (error) {
|
|
3479
|
+
const err = error;
|
|
3474
3480
|
if (err.message && err.message.includes("timeout")) {
|
|
3475
3481
|
serverLogger2.error("Graceful shutdown timeout, forcing exit", err);
|
|
3476
3482
|
} else {
|
|
@@ -3483,8 +3489,8 @@ function createGracefulShutdown(shutdownServer, config) {
|
|
|
3483
3489
|
function registerShutdownHandlers(shutdown) {
|
|
3484
3490
|
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
3485
3491
|
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
3486
|
-
process.on("uncaughtException", (
|
|
3487
|
-
serverLogger2.error("Uncaught exception",
|
|
3492
|
+
process.on("uncaughtException", (error) => {
|
|
3493
|
+
serverLogger2.error("Uncaught exception", error);
|
|
3488
3494
|
shutdown("UNCAUGHT_EXCEPTION");
|
|
3489
3495
|
});
|
|
3490
3496
|
process.on("unhandledRejection", (reason, promise) => {
|