@prisma-next/core-control-plane 0.3.0-dev.88 → 0.3.0-dev.89
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/errors.d.mts +2 -2
- package/dist/errors.mjs +10 -10
- package/dist/errors.mjs.map +1 -1
- package/package.json +6 -6
- package/src/errors.ts +13 -13
package/dist/errors.d.mts
CHANGED
|
@@ -35,7 +35,7 @@ interface CliErrorConflict {
|
|
|
35
35
|
*/
|
|
36
36
|
declare class CliStructuredError extends Error {
|
|
37
37
|
readonly code: string;
|
|
38
|
-
readonly domain: 'CLI' | '
|
|
38
|
+
readonly domain: 'CLI' | 'RUN';
|
|
39
39
|
readonly severity: 'error' | 'warn' | 'info';
|
|
40
40
|
readonly why: string | undefined;
|
|
41
41
|
readonly fix: string | undefined;
|
|
@@ -46,7 +46,7 @@ declare class CliStructuredError extends Error {
|
|
|
46
46
|
readonly meta: Record<string, unknown> | undefined;
|
|
47
47
|
readonly docsUrl: string | undefined;
|
|
48
48
|
constructor(code: string, summary: string, options?: {
|
|
49
|
-
readonly domain?: 'CLI' | '
|
|
49
|
+
readonly domain?: 'CLI' | 'RUN';
|
|
50
50
|
readonly severity?: 'error' | 'warn' | 'info';
|
|
51
51
|
readonly why?: string;
|
|
52
52
|
readonly fix?: string;
|
package/dist/errors.mjs
CHANGED
|
@@ -35,7 +35,7 @@ var CliStructuredError = class extends Error {
|
|
|
35
35
|
toEnvelope() {
|
|
36
36
|
return {
|
|
37
37
|
ok: false,
|
|
38
|
-
code: `${this.domain === "CLI" ? "PN-CLI-" : "PN-
|
|
38
|
+
code: `${this.domain === "CLI" ? "PN-CLI-" : "PN-RUN-"}${this.code}`,
|
|
39
39
|
domain: this.domain,
|
|
40
40
|
severity: this.severity,
|
|
41
41
|
summary: this.message,
|
|
@@ -53,7 +53,7 @@ var CliStructuredError = class extends Error {
|
|
|
53
53
|
static is(error) {
|
|
54
54
|
if (!(error instanceof Error)) return false;
|
|
55
55
|
const candidate = error;
|
|
56
|
-
return candidate.name === "CliStructuredError" && typeof candidate.code === "string" && (candidate.domain === "CLI" || candidate.domain === "
|
|
56
|
+
return candidate.name === "CliStructuredError" && typeof candidate.code === "string" && (candidate.domain === "CLI" || candidate.domain === "RUN") && typeof candidate.toEnvelope === "function";
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
59
|
/**
|
|
@@ -220,7 +220,7 @@ function errorConfigValidation(field, options) {
|
|
|
220
220
|
*/
|
|
221
221
|
function errorMarkerMissing(options) {
|
|
222
222
|
return new CliStructuredError("3001", "Database not signed", {
|
|
223
|
-
domain: "
|
|
223
|
+
domain: "RUN",
|
|
224
224
|
why: options?.why ?? "No database signature (marker) found",
|
|
225
225
|
fix: "Run `prisma-next db sign --db <url>` to sign the database"
|
|
226
226
|
});
|
|
@@ -230,7 +230,7 @@ function errorMarkerMissing(options) {
|
|
|
230
230
|
*/
|
|
231
231
|
function errorHashMismatch(options) {
|
|
232
232
|
return new CliStructuredError("3002", "Hash mismatch", {
|
|
233
|
-
domain: "
|
|
233
|
+
domain: "RUN",
|
|
234
234
|
why: options?.why ?? "Contract hash does not match database marker",
|
|
235
235
|
fix: "Migrate database or re-sign if intentional",
|
|
236
236
|
...options?.expected || options?.actual ? { meta: {
|
|
@@ -244,7 +244,7 @@ function errorHashMismatch(options) {
|
|
|
244
244
|
*/
|
|
245
245
|
function errorTargetMismatch(expected, actual, options) {
|
|
246
246
|
return new CliStructuredError("3003", "Target mismatch", {
|
|
247
|
-
domain: "
|
|
247
|
+
domain: "RUN",
|
|
248
248
|
why: options?.why ?? `Contract target does not match config target (expected: ${expected}, actual: ${actual})`,
|
|
249
249
|
fix: "Align contract target and config target",
|
|
250
250
|
meta: {
|
|
@@ -259,7 +259,7 @@ function errorTargetMismatch(expected, actual, options) {
|
|
|
259
259
|
*/
|
|
260
260
|
function errorMarkerRequired(options) {
|
|
261
261
|
return new CliStructuredError("3010", "Database must be signed first", {
|
|
262
|
-
domain: "
|
|
262
|
+
domain: "RUN",
|
|
263
263
|
why: options?.why ?? "No database signature (marker) found",
|
|
264
264
|
fix: options?.fix ?? "Run `prisma-next db init` first to sign the database"
|
|
265
265
|
});
|
|
@@ -270,7 +270,7 @@ function errorMarkerRequired(options) {
|
|
|
270
270
|
*/
|
|
271
271
|
function errorSchemaVerificationFailed(options) {
|
|
272
272
|
return new CliStructuredError("3004", options.summary, {
|
|
273
|
-
domain: "
|
|
273
|
+
domain: "RUN",
|
|
274
274
|
why: "Database schema does not satisfy the contract",
|
|
275
275
|
fix: "Run `prisma-next db update` to reconcile, or adjust your contract to match the database",
|
|
276
276
|
meta: {
|
|
@@ -284,7 +284,7 @@ function errorSchemaVerificationFailed(options) {
|
|
|
284
284
|
*/
|
|
285
285
|
function errorRunnerFailed(summary, options) {
|
|
286
286
|
return new CliStructuredError("3020", summary, {
|
|
287
|
-
domain: "
|
|
287
|
+
domain: "RUN",
|
|
288
288
|
why: options?.why ?? "Migration runner failed",
|
|
289
289
|
fix: options?.fix ?? "Inspect the reported conflict and reconcile schema drift",
|
|
290
290
|
...options?.meta ? { meta: options.meta } : {}
|
|
@@ -297,7 +297,7 @@ const ERROR_CODE_DESTRUCTIVE_CHANGES = "3030";
|
|
|
297
297
|
*/
|
|
298
298
|
function errorDestructiveChanges(summary, options) {
|
|
299
299
|
return new CliStructuredError(ERROR_CODE_DESTRUCTIVE_CHANGES, summary, {
|
|
300
|
-
domain: "
|
|
300
|
+
domain: "RUN",
|
|
301
301
|
why: options?.why ?? "Planned operations include destructive changes that require confirmation",
|
|
302
302
|
fix: options?.fix ?? "Re-run with `-y` to apply, or use `--dry-run` to preview first",
|
|
303
303
|
...options?.meta ? { meta: options.meta } : {}
|
|
@@ -308,7 +308,7 @@ function errorDestructiveChanges(summary, options) {
|
|
|
308
308
|
*/
|
|
309
309
|
function errorRuntime(summary, options) {
|
|
310
310
|
return new CliStructuredError("3000", summary, {
|
|
311
|
-
domain: "
|
|
311
|
+
domain: "RUN",
|
|
312
312
|
...options?.why ? { why: options.why } : { why: "Verification failed" },
|
|
313
313
|
...options?.fix ? { fix: options.fix } : { fix: "Check contract and database state" },
|
|
314
314
|
...options?.meta ? { meta: options.meta } : {}
|
package/dist/errors.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { ifDefined } from '@prisma-next/utils/defined';\nimport type { SchemaIssue, VerifyDatabaseSchemaResult } from './types';\n\n/**\n * CLI error envelope for output formatting.\n * This is the serialized form of a CliStructuredError.\n */\nexport interface CliErrorEnvelope {\n readonly ok: false;\n readonly code: string;\n readonly domain: string;\n readonly severity: 'error' | 'warn' | 'info';\n readonly summary: string;\n readonly why: string | undefined;\n readonly fix: string | undefined;\n readonly where:\n | {\n readonly path: string | undefined;\n readonly line: number | undefined;\n }\n | undefined;\n readonly meta: Record<string, unknown> | undefined;\n readonly docsUrl: string | undefined;\n}\n\n/**\n * Minimal conflict data structure expected by CLI output.\n */\nexport interface CliErrorConflict {\n readonly kind: string;\n readonly summary: string;\n readonly why?: string;\n}\n\n/**\n * Structured CLI error that contains all information needed for error envelopes.\n * Call sites throw these errors with full context.\n */\nexport class CliStructuredError extends Error {\n readonly code: string;\n readonly domain: 'CLI' | 'RTM';\n readonly severity: 'error' | 'warn' | 'info';\n readonly why: string | undefined;\n readonly fix: string | undefined;\n readonly where:\n | {\n readonly path: string | undefined;\n readonly line: number | undefined;\n }\n | undefined;\n readonly meta: Record<string, unknown> | undefined;\n readonly docsUrl: string | undefined;\n\n constructor(\n code: string,\n summary: string,\n options?: {\n readonly domain?: 'CLI' | 'RTM';\n readonly severity?: 'error' | 'warn' | 'info';\n readonly why?: string;\n readonly fix?: string;\n readonly where?: { readonly path?: string; readonly line?: number };\n readonly meta?: Record<string, unknown>;\n readonly docsUrl?: string;\n },\n ) {\n super(summary);\n this.name = 'CliStructuredError';\n this.code = code;\n this.domain = options?.domain ?? 'CLI';\n this.severity = options?.severity ?? 'error';\n this.why = options?.why;\n this.fix = options?.fix === options?.why ? undefined : options?.fix;\n this.where = options?.where\n ? {\n path: options.where.path,\n line: options.where.line,\n }\n : undefined;\n this.meta = options?.meta;\n this.docsUrl = options?.docsUrl;\n }\n\n /**\n * Converts this error to a CLI error envelope for output formatting.\n */\n toEnvelope(): CliErrorEnvelope {\n const codePrefix = this.domain === 'CLI' ? 'PN-CLI-' : 'PN-RTM-';\n return {\n ok: false as const,\n code: `${codePrefix}${this.code}`,\n domain: this.domain,\n severity: this.severity,\n summary: this.message,\n why: this.why,\n fix: this.fix,\n where: this.where,\n meta: this.meta,\n docsUrl: this.docsUrl,\n };\n }\n\n /**\n * Type guard to check if an error is a CliStructuredError.\n * Uses duck-typing to work across module boundaries where instanceof may fail.\n */\n static is(error: unknown): error is CliStructuredError {\n if (!(error instanceof Error)) {\n return false;\n }\n const candidate = error as CliStructuredError;\n return (\n candidate.name === 'CliStructuredError' &&\n typeof candidate.code === 'string' &&\n (candidate.domain === 'CLI' || candidate.domain === 'RTM') &&\n typeof candidate.toEnvelope === 'function'\n );\n }\n}\n\n// ============================================================================\n// Config Errors (PN-CLI-4001-4007)\n// ============================================================================\n\n/**\n * Config file not found or missing.\n */\nexport function errorConfigFileNotFound(\n configPath?: string,\n options?: {\n readonly why?: string;\n },\n): CliStructuredError {\n return new CliStructuredError('4001', 'Config file not found', {\n domain: 'CLI',\n ...(options?.why ? { why: options.why } : { why: 'Config file not found' }),\n fix: \"Run 'prisma-next init' to create a config file\",\n docsUrl: 'https://prisma-next.dev/docs/cli/config',\n ...(configPath ? { where: { path: configPath } } : {}),\n });\n}\n\n/**\n * Contract configuration missing from config.\n */\nexport function errorContractConfigMissing(options?: {\n readonly why?: string;\n}): CliStructuredError {\n return new CliStructuredError('4002', 'Contract configuration missing', {\n domain: 'CLI',\n why: options?.why ?? 'The contract configuration is required for emit',\n fix: 'Add contract configuration to your prisma-next.config.ts',\n docsUrl: 'https://prisma-next.dev/docs/cli/contract-emit',\n });\n}\n\n/**\n * Contract validation failed.\n */\nexport function errorContractValidationFailed(\n reason: string,\n options?: {\n readonly where?: { readonly path?: string; readonly line?: number };\n },\n): CliStructuredError {\n return new CliStructuredError('4003', 'Contract validation failed', {\n domain: 'CLI',\n why: reason,\n fix: 'Re-run `prisma-next contract emit`, or fix the contract file and try again',\n docsUrl: 'https://prisma-next.dev/docs/contracts',\n ...(options?.where ? { where: options.where } : {}),\n });\n}\n\n/**\n * File not found.\n */\nexport function errorFileNotFound(\n filePath: string,\n options?: {\n readonly why?: string;\n readonly fix?: string;\n readonly docsUrl?: string;\n },\n): CliStructuredError {\n return new CliStructuredError('4004', 'File not found', {\n domain: 'CLI',\n why: options?.why ?? `File not found: ${filePath}`,\n fix: options?.fix ?? 'Check that the file path is correct',\n where: { path: filePath },\n ...(options?.docsUrl ? { docsUrl: options.docsUrl } : {}),\n });\n}\n\n/**\n * Database connection is required but not provided.\n */\nexport function errorDatabaseConnectionRequired(options?: {\n readonly why?: string;\n readonly commandName?: string;\n readonly retryCommand?: string;\n}): CliStructuredError {\n const runHint = options?.retryCommand\n ? `Run \\`${options.retryCommand}\\``\n : options?.commandName\n ? `Run \\`prisma-next ${options.commandName} --db <url>\\``\n : 'Provide `--db <url>`';\n return new CliStructuredError('4005', 'Database connection is required', {\n domain: 'CLI',\n why: options?.why ?? 'Database connection is required for this command',\n fix: `${runHint}, or set \\`db: { connection: \"postgres://…\" }\\` in prisma-next.config.ts`,\n });\n}\n\n/**\n * Query runner factory is required but not provided in config.\n */\nexport function errorQueryRunnerFactoryRequired(options?: {\n readonly why?: string;\n}): CliStructuredError {\n return new CliStructuredError('4006', 'Query runner factory is required', {\n domain: 'CLI',\n why: options?.why ?? 'Config.db.queryRunnerFactory is required for db verify',\n fix: 'Add db.queryRunnerFactory to prisma-next.config.ts',\n docsUrl: 'https://prisma-next.dev/docs/cli/db-verify',\n });\n}\n\n/**\n * Family verify.readMarker is required but not provided.\n */\nexport function errorFamilyReadMarkerSqlRequired(options?: {\n readonly why?: string;\n}): CliStructuredError {\n return new CliStructuredError('4007', 'Family readMarker() is required', {\n domain: 'CLI',\n why: options?.why ?? 'Family verify.readMarker is required for db verify',\n fix: 'Ensure family.verify.readMarker() is exported by your family package',\n docsUrl: 'https://prisma-next.dev/docs/cli/db-verify',\n });\n}\n\n/**\n * JSON output format not supported.\n */\nexport function errorJsonFormatNotSupported(options: {\n readonly command: string;\n readonly format: string;\n readonly supportedFormats: readonly string[];\n}): CliStructuredError {\n return new CliStructuredError('4008', 'Unsupported JSON format', {\n domain: 'CLI',\n why: `The ${options.command} command does not support --json ${options.format}`,\n fix: `Use --json ${options.supportedFormats.join(' or ')}, or omit --json for human output`,\n meta: {\n command: options.command,\n format: options.format,\n supportedFormats: options.supportedFormats,\n },\n });\n}\n\n/**\n * Driver is required for DB-connected commands but not provided.\n */\nexport function errorDriverRequired(options?: { readonly why?: string }): CliStructuredError {\n return new CliStructuredError('4010', 'Driver is required for DB-connected commands', {\n domain: 'CLI',\n why: options?.why ?? 'Config.driver is required for DB-connected commands',\n fix: 'Add a control-plane driver to prisma-next.config.ts (e.g. import a driver descriptor and set `driver: postgresDriver`)',\n docsUrl: 'https://prisma-next.dev/docs/cli/config',\n });\n}\n\n/**\n * Contract requires extension packs that are not provided by config descriptors.\n */\nexport function errorContractMissingExtensionPacks(options: {\n readonly missingExtensionPacks: readonly string[];\n readonly providedComponentIds: readonly string[];\n}): CliStructuredError {\n const missing = [...options.missingExtensionPacks].sort();\n return new CliStructuredError('4011', 'Missing extension packs in config', {\n domain: 'CLI',\n why:\n missing.length === 1\n ? `Contract requires extension pack '${missing[0]}', but CLI config does not provide a matching descriptor.`\n : `Contract requires extension packs ${missing.map((p) => `'${p}'`).join(', ')}, but CLI config does not provide matching descriptors.`,\n fix: 'Add the missing extension descriptors to `extensions` in prisma-next.config.ts',\n docsUrl: 'https://prisma-next.dev/docs/cli/config',\n meta: {\n missingExtensionPacks: missing,\n providedComponentIds: [...options.providedComponentIds].sort(),\n },\n });\n}\n\n/**\n * Migration planning failed due to conflicts.\n */\nexport function errorMigrationPlanningFailed(options: {\n readonly conflicts: readonly CliErrorConflict[];\n readonly why?: string;\n}): CliStructuredError {\n // Build \"why\" from conflict summaries - these contain the actual problem description\n const conflictSummaries = options.conflicts.map((c) => c.summary);\n const computedWhy = options.why ?? conflictSummaries.join('\\n');\n\n // Build \"fix\" from conflict \"why\" fields - these contain actionable advice\n const conflictFixes = options.conflicts\n .map((c) => c.why)\n .filter((why): why is string => typeof why === 'string');\n const computedFix =\n conflictFixes.length > 0\n ? conflictFixes.join('\\n')\n : 'Use `db verify --schema-only` to inspect conflicts, or ensure the database is empty';\n\n return new CliStructuredError('4020', 'Migration planning failed', {\n domain: 'CLI',\n why: computedWhy,\n fix: computedFix,\n meta: { conflicts: options.conflicts },\n docsUrl: 'https://prisma-next.dev/docs/cli/db-init',\n });\n}\n\n/**\n * Target does not support migrations (missing createPlanner/createRunner).\n */\nexport function errorTargetMigrationNotSupported(options?: {\n readonly why?: string;\n}): CliStructuredError {\n return new CliStructuredError('4021', 'Target does not support migrations', {\n domain: 'CLI',\n why: options?.why ?? 'The configured target does not provide migration planner/runner',\n fix: 'Select a target that provides migrations (it must export `target.migrations` for db init)',\n docsUrl: 'https://prisma-next.dev/docs/cli/db-init',\n });\n}\n\n/**\n * Config validation error (missing required fields).\n */\nexport function errorConfigValidation(\n field: string,\n options?: {\n readonly why?: string;\n },\n): CliStructuredError {\n return new CliStructuredError('4009', 'Config validation error', {\n domain: 'CLI',\n why: options?.why ?? `Config must have a \"${field}\" field`,\n fix: 'Check your prisma-next.config.ts and ensure all required fields are provided',\n docsUrl: 'https://prisma-next.dev/docs/cli/config',\n });\n}\n\n// ============================================================================\n// Runtime Errors (PN-RTM-3000-3030)\n// ============================================================================\n\n/**\n * Contract marker not found in database.\n */\nexport function errorMarkerMissing(options?: {\n readonly why?: string;\n readonly dbUrl?: string;\n}): CliStructuredError {\n return new CliStructuredError('3001', 'Database not signed', {\n domain: 'RTM',\n why: options?.why ?? 'No database signature (marker) found',\n fix: 'Run `prisma-next db sign --db <url>` to sign the database',\n });\n}\n\n/**\n * Contract hash does not match database marker.\n */\nexport function errorHashMismatch(options?: {\n readonly why?: string;\n readonly expected?: string;\n readonly actual?: string;\n}): CliStructuredError {\n return new CliStructuredError('3002', 'Hash mismatch', {\n domain: 'RTM',\n why: options?.why ?? 'Contract hash does not match database marker',\n fix: 'Migrate database or re-sign if intentional',\n ...(options?.expected || options?.actual\n ? {\n meta: {\n ...(options.expected ? { expected: options.expected } : {}),\n ...(options.actual ? { actual: options.actual } : {}),\n },\n }\n : {}),\n });\n}\n\n/**\n * Contract target does not match config target.\n */\nexport function errorTargetMismatch(\n expected: string,\n actual: string,\n options?: {\n readonly why?: string;\n },\n): CliStructuredError {\n return new CliStructuredError('3003', 'Target mismatch', {\n domain: 'RTM',\n why:\n options?.why ??\n `Contract target does not match config target (expected: ${expected}, actual: ${actual})`,\n fix: 'Align contract target and config target',\n meta: { expected, actual },\n });\n}\n\n/**\n * Database marker is required but not found.\n * Used by commands that require a pre-existing marker as a precondition.\n */\nexport function errorMarkerRequired(options?: {\n readonly why?: string;\n readonly fix?: string;\n}): CliStructuredError {\n return new CliStructuredError('3010', 'Database must be signed first', {\n domain: 'RTM',\n why: options?.why ?? 'No database signature (marker) found',\n fix: options?.fix ?? 'Run `prisma-next db init` first to sign the database',\n });\n}\n\n/**\n * Schema verification found mismatches between the database and the contract.\n * The full verification tree is preserved in `meta.verificationResult`.\n */\nexport function errorSchemaVerificationFailed(options: {\n readonly summary: string;\n readonly verificationResult: VerifyDatabaseSchemaResult;\n readonly issues?: readonly SchemaIssue[];\n}): CliStructuredError {\n return new CliStructuredError('3004', options.summary, {\n domain: 'RTM',\n why: 'Database schema does not satisfy the contract',\n fix: 'Run `prisma-next db update` to reconcile, or adjust your contract to match the database',\n meta: {\n verificationResult: options.verificationResult,\n ...ifDefined('issues', options.issues),\n },\n });\n}\n\n/**\n * Migration runner failed during execution.\n */\nexport function errorRunnerFailed(\n summary: string,\n options?: {\n readonly why?: string;\n readonly fix?: string;\n readonly meta?: Record<string, unknown>;\n },\n): CliStructuredError {\n return new CliStructuredError('3020', summary, {\n domain: 'RTM',\n why: options?.why ?? 'Migration runner failed',\n fix: options?.fix ?? 'Inspect the reported conflict and reconcile schema drift',\n ...(options?.meta ? { meta: options.meta } : {}),\n });\n}\n\n/** Error code for destructive changes that require explicit confirmation. */\nexport const ERROR_CODE_DESTRUCTIVE_CHANGES = '3030';\n\n/**\n * Destructive operations require explicit confirmation via -y/--yes.\n */\nexport function errorDestructiveChanges(\n summary: string,\n options?: {\n readonly why?: string;\n readonly fix?: string;\n readonly meta?: Record<string, unknown>;\n },\n): CliStructuredError {\n return new CliStructuredError(ERROR_CODE_DESTRUCTIVE_CHANGES, summary, {\n domain: 'RTM',\n why: options?.why ?? 'Planned operations include destructive changes that require confirmation',\n fix: options?.fix ?? 'Re-run with `-y` to apply, or use `--dry-run` to preview first',\n ...(options?.meta ? { meta: options.meta } : {}),\n });\n}\n\n/**\n * Generic runtime error.\n */\nexport function errorRuntime(\n summary: string,\n options?: {\n readonly why?: string;\n readonly fix?: string;\n readonly meta?: Record<string, unknown>;\n },\n): CliStructuredError {\n return new CliStructuredError('3000', summary, {\n domain: 'RTM',\n ...(options?.why ? { why: options.why } : { why: 'Verification failed' }),\n ...(options?.fix ? { fix: options.fix } : { fix: 'Check contract and database state' }),\n ...(options?.meta ? { meta: options.meta } : {}),\n });\n}\n\n// ============================================================================\n// Generic Error\n// ============================================================================\n\n/**\n * Generic unexpected error.\n */\nexport function errorUnexpected(\n message: string,\n options?: {\n readonly why?: string;\n readonly fix?: string;\n },\n): CliStructuredError {\n return new CliStructuredError('4999', 'Unexpected error', {\n domain: 'CLI',\n why: options?.why ?? message,\n fix: options?.fix ?? 'Check the error message and try again',\n });\n}\n"],"mappings":";;;;;;;AAsCA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,AAAS;CAC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QAAQ,SAAS;EAC7C,QAAQ;EACR,KAAK,SAAS,OAAO;EACrB,KAAK,SAAS,OAAO;EACrB,GAAI,SAAS,OAAO,EAAE,MAAM,QAAQ,MAAM,GAAG,EAAE;EAChD,CAAC;;;AAIJ,MAAa,iCAAiC;;;;AAK9C,SAAgB,wBACd,SACA,SAKoB;AACpB,QAAO,IAAI,mBAAmB,gCAAgC,SAAS;EACrE,QAAQ;EACR,KAAK,SAAS,OAAO;EACrB,KAAK,SAAS,OAAO;EACrB,GAAI,SAAS,OAAO,EAAE,MAAM,QAAQ,MAAM,GAAG,EAAE;EAChD,CAAC;;;;;AAMJ,SAAgB,aACd,SACA,SAKoB;AACpB,QAAO,IAAI,mBAAmB,QAAQ,SAAS;EAC7C,QAAQ;EACR,GAAI,SAAS,MAAM,EAAE,KAAK,QAAQ,KAAK,GAAG,EAAE,KAAK,uBAAuB;EACxE,GAAI,SAAS,MAAM,EAAE,KAAK,QAAQ,KAAK,GAAG,EAAE,KAAK,qCAAqC;EACtF,GAAI,SAAS,OAAO,EAAE,MAAM,QAAQ,MAAM,GAAG,EAAE;EAChD,CAAC;;;;;AAUJ,SAAgB,gBACd,SACA,SAIoB;AACpB,QAAO,IAAI,mBAAmB,QAAQ,oBAAoB;EACxD,QAAQ;EACR,KAAK,SAAS,OAAO;EACrB,KAAK,SAAS,OAAO;EACtB,CAAC"}
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { ifDefined } from '@prisma-next/utils/defined';\nimport type { SchemaIssue, VerifyDatabaseSchemaResult } from './types';\n\n/**\n * CLI error envelope for output formatting.\n * This is the serialized form of a CliStructuredError.\n */\nexport interface CliErrorEnvelope {\n readonly ok: false;\n readonly code: string;\n readonly domain: string;\n readonly severity: 'error' | 'warn' | 'info';\n readonly summary: string;\n readonly why: string | undefined;\n readonly fix: string | undefined;\n readonly where:\n | {\n readonly path: string | undefined;\n readonly line: number | undefined;\n }\n | undefined;\n readonly meta: Record<string, unknown> | undefined;\n readonly docsUrl: string | undefined;\n}\n\n/**\n * Minimal conflict data structure expected by CLI output.\n */\nexport interface CliErrorConflict {\n readonly kind: string;\n readonly summary: string;\n readonly why?: string;\n}\n\n/**\n * Structured CLI error that contains all information needed for error envelopes.\n * Call sites throw these errors with full context.\n */\nexport class CliStructuredError extends Error {\n readonly code: string;\n readonly domain: 'CLI' | 'RUN';\n readonly severity: 'error' | 'warn' | 'info';\n readonly why: string | undefined;\n readonly fix: string | undefined;\n readonly where:\n | {\n readonly path: string | undefined;\n readonly line: number | undefined;\n }\n | undefined;\n readonly meta: Record<string, unknown> | undefined;\n readonly docsUrl: string | undefined;\n\n constructor(\n code: string,\n summary: string,\n options?: {\n readonly domain?: 'CLI' | 'RUN';\n readonly severity?: 'error' | 'warn' | 'info';\n readonly why?: string;\n readonly fix?: string;\n readonly where?: { readonly path?: string; readonly line?: number };\n readonly meta?: Record<string, unknown>;\n readonly docsUrl?: string;\n },\n ) {\n super(summary);\n this.name = 'CliStructuredError';\n this.code = code;\n this.domain = options?.domain ?? 'CLI';\n this.severity = options?.severity ?? 'error';\n this.why = options?.why;\n this.fix = options?.fix === options?.why ? undefined : options?.fix;\n this.where = options?.where\n ? {\n path: options.where.path,\n line: options.where.line,\n }\n : undefined;\n this.meta = options?.meta;\n this.docsUrl = options?.docsUrl;\n }\n\n /**\n * Converts this error to a CLI error envelope for output formatting.\n */\n toEnvelope(): CliErrorEnvelope {\n const codePrefix = this.domain === 'CLI' ? 'PN-CLI-' : 'PN-RUN-';\n return {\n ok: false as const,\n code: `${codePrefix}${this.code}`,\n domain: this.domain,\n severity: this.severity,\n summary: this.message,\n why: this.why,\n fix: this.fix,\n where: this.where,\n meta: this.meta,\n docsUrl: this.docsUrl,\n };\n }\n\n /**\n * Type guard to check if an error is a CliStructuredError.\n * Uses duck-typing to work across module boundaries where instanceof may fail.\n */\n static is(error: unknown): error is CliStructuredError {\n if (!(error instanceof Error)) {\n return false;\n }\n const candidate = error as CliStructuredError;\n return (\n candidate.name === 'CliStructuredError' &&\n typeof candidate.code === 'string' &&\n (candidate.domain === 'CLI' || candidate.domain === 'RUN') &&\n typeof candidate.toEnvelope === 'function'\n );\n }\n}\n\n// ============================================================================\n// Config Errors (PN-CLI-4001-4007)\n// ============================================================================\n\n/**\n * Config file not found or missing.\n */\nexport function errorConfigFileNotFound(\n configPath?: string,\n options?: {\n readonly why?: string;\n },\n): CliStructuredError {\n return new CliStructuredError('4001', 'Config file not found', {\n domain: 'CLI',\n ...(options?.why ? { why: options.why } : { why: 'Config file not found' }),\n fix: \"Run 'prisma-next init' to create a config file\",\n docsUrl: 'https://prisma-next.dev/docs/cli/config',\n ...(configPath ? { where: { path: configPath } } : {}),\n });\n}\n\n/**\n * Contract configuration missing from config.\n */\nexport function errorContractConfigMissing(options?: {\n readonly why?: string;\n}): CliStructuredError {\n return new CliStructuredError('4002', 'Contract configuration missing', {\n domain: 'CLI',\n why: options?.why ?? 'The contract configuration is required for emit',\n fix: 'Add contract configuration to your prisma-next.config.ts',\n docsUrl: 'https://prisma-next.dev/docs/cli/contract-emit',\n });\n}\n\n/**\n * Contract validation failed.\n */\nexport function errorContractValidationFailed(\n reason: string,\n options?: {\n readonly where?: { readonly path?: string; readonly line?: number };\n },\n): CliStructuredError {\n return new CliStructuredError('4003', 'Contract validation failed', {\n domain: 'CLI',\n why: reason,\n fix: 'Re-run `prisma-next contract emit`, or fix the contract file and try again',\n docsUrl: 'https://prisma-next.dev/docs/contracts',\n ...(options?.where ? { where: options.where } : {}),\n });\n}\n\n/**\n * File not found.\n */\nexport function errorFileNotFound(\n filePath: string,\n options?: {\n readonly why?: string;\n readonly fix?: string;\n readonly docsUrl?: string;\n },\n): CliStructuredError {\n return new CliStructuredError('4004', 'File not found', {\n domain: 'CLI',\n why: options?.why ?? `File not found: ${filePath}`,\n fix: options?.fix ?? 'Check that the file path is correct',\n where: { path: filePath },\n ...(options?.docsUrl ? { docsUrl: options.docsUrl } : {}),\n });\n}\n\n/**\n * Database connection is required but not provided.\n */\nexport function errorDatabaseConnectionRequired(options?: {\n readonly why?: string;\n readonly commandName?: string;\n readonly retryCommand?: string;\n}): CliStructuredError {\n const runHint = options?.retryCommand\n ? `Run \\`${options.retryCommand}\\``\n : options?.commandName\n ? `Run \\`prisma-next ${options.commandName} --db <url>\\``\n : 'Provide `--db <url>`';\n return new CliStructuredError('4005', 'Database connection is required', {\n domain: 'CLI',\n why: options?.why ?? 'Database connection is required for this command',\n fix: `${runHint}, or set \\`db: { connection: \"postgres://…\" }\\` in prisma-next.config.ts`,\n });\n}\n\n/**\n * Query runner factory is required but not provided in config.\n */\nexport function errorQueryRunnerFactoryRequired(options?: {\n readonly why?: string;\n}): CliStructuredError {\n return new CliStructuredError('4006', 'Query runner factory is required', {\n domain: 'CLI',\n why: options?.why ?? 'Config.db.queryRunnerFactory is required for db verify',\n fix: 'Add db.queryRunnerFactory to prisma-next.config.ts',\n docsUrl: 'https://prisma-next.dev/docs/cli/db-verify',\n });\n}\n\n/**\n * Family verify.readMarker is required but not provided.\n */\nexport function errorFamilyReadMarkerSqlRequired(options?: {\n readonly why?: string;\n}): CliStructuredError {\n return new CliStructuredError('4007', 'Family readMarker() is required', {\n domain: 'CLI',\n why: options?.why ?? 'Family verify.readMarker is required for db verify',\n fix: 'Ensure family.verify.readMarker() is exported by your family package',\n docsUrl: 'https://prisma-next.dev/docs/cli/db-verify',\n });\n}\n\n/**\n * JSON output format not supported.\n */\nexport function errorJsonFormatNotSupported(options: {\n readonly command: string;\n readonly format: string;\n readonly supportedFormats: readonly string[];\n}): CliStructuredError {\n return new CliStructuredError('4008', 'Unsupported JSON format', {\n domain: 'CLI',\n why: `The ${options.command} command does not support --json ${options.format}`,\n fix: `Use --json ${options.supportedFormats.join(' or ')}, or omit --json for human output`,\n meta: {\n command: options.command,\n format: options.format,\n supportedFormats: options.supportedFormats,\n },\n });\n}\n\n/**\n * Driver is required for DB-connected commands but not provided.\n */\nexport function errorDriverRequired(options?: { readonly why?: string }): CliStructuredError {\n return new CliStructuredError('4010', 'Driver is required for DB-connected commands', {\n domain: 'CLI',\n why: options?.why ?? 'Config.driver is required for DB-connected commands',\n fix: 'Add a control-plane driver to prisma-next.config.ts (e.g. import a driver descriptor and set `driver: postgresDriver`)',\n docsUrl: 'https://prisma-next.dev/docs/cli/config',\n });\n}\n\n/**\n * Contract requires extension packs that are not provided by config descriptors.\n */\nexport function errorContractMissingExtensionPacks(options: {\n readonly missingExtensionPacks: readonly string[];\n readonly providedComponentIds: readonly string[];\n}): CliStructuredError {\n const missing = [...options.missingExtensionPacks].sort();\n return new CliStructuredError('4011', 'Missing extension packs in config', {\n domain: 'CLI',\n why:\n missing.length === 1\n ? `Contract requires extension pack '${missing[0]}', but CLI config does not provide a matching descriptor.`\n : `Contract requires extension packs ${missing.map((p) => `'${p}'`).join(', ')}, but CLI config does not provide matching descriptors.`,\n fix: 'Add the missing extension descriptors to `extensions` in prisma-next.config.ts',\n docsUrl: 'https://prisma-next.dev/docs/cli/config',\n meta: {\n missingExtensionPacks: missing,\n providedComponentIds: [...options.providedComponentIds].sort(),\n },\n });\n}\n\n/**\n * Migration planning failed due to conflicts.\n */\nexport function errorMigrationPlanningFailed(options: {\n readonly conflicts: readonly CliErrorConflict[];\n readonly why?: string;\n}): CliStructuredError {\n // Build \"why\" from conflict summaries - these contain the actual problem description\n const conflictSummaries = options.conflicts.map((c) => c.summary);\n const computedWhy = options.why ?? conflictSummaries.join('\\n');\n\n // Build \"fix\" from conflict \"why\" fields - these contain actionable advice\n const conflictFixes = options.conflicts\n .map((c) => c.why)\n .filter((why): why is string => typeof why === 'string');\n const computedFix =\n conflictFixes.length > 0\n ? conflictFixes.join('\\n')\n : 'Use `db verify --schema-only` to inspect conflicts, or ensure the database is empty';\n\n return new CliStructuredError('4020', 'Migration planning failed', {\n domain: 'CLI',\n why: computedWhy,\n fix: computedFix,\n meta: { conflicts: options.conflicts },\n docsUrl: 'https://prisma-next.dev/docs/cli/db-init',\n });\n}\n\n/**\n * Target does not support migrations (missing createPlanner/createRunner).\n */\nexport function errorTargetMigrationNotSupported(options?: {\n readonly why?: string;\n}): CliStructuredError {\n return new CliStructuredError('4021', 'Target does not support migrations', {\n domain: 'CLI',\n why: options?.why ?? 'The configured target does not provide migration planner/runner',\n fix: 'Select a target that provides migrations (it must export `target.migrations` for db init)',\n docsUrl: 'https://prisma-next.dev/docs/cli/db-init',\n });\n}\n\n/**\n * Config validation error (missing required fields).\n */\nexport function errorConfigValidation(\n field: string,\n options?: {\n readonly why?: string;\n },\n): CliStructuredError {\n return new CliStructuredError('4009', 'Config validation error', {\n domain: 'CLI',\n why: options?.why ?? `Config must have a \"${field}\" field`,\n fix: 'Check your prisma-next.config.ts and ensure all required fields are provided',\n docsUrl: 'https://prisma-next.dev/docs/cli/config',\n });\n}\n\n// ============================================================================\n// Runtime Errors (PN-RUN-3000-3030)\n// ============================================================================\n\n/**\n * Contract marker not found in database.\n */\nexport function errorMarkerMissing(options?: {\n readonly why?: string;\n readonly dbUrl?: string;\n}): CliStructuredError {\n return new CliStructuredError('3001', 'Database not signed', {\n domain: 'RUN',\n why: options?.why ?? 'No database signature (marker) found',\n fix: 'Run `prisma-next db sign --db <url>` to sign the database',\n });\n}\n\n/**\n * Contract hash does not match database marker.\n */\nexport function errorHashMismatch(options?: {\n readonly why?: string;\n readonly expected?: string;\n readonly actual?: string;\n}): CliStructuredError {\n return new CliStructuredError('3002', 'Hash mismatch', {\n domain: 'RUN',\n why: options?.why ?? 'Contract hash does not match database marker',\n fix: 'Migrate database or re-sign if intentional',\n ...(options?.expected || options?.actual\n ? {\n meta: {\n ...(options.expected ? { expected: options.expected } : {}),\n ...(options.actual ? { actual: options.actual } : {}),\n },\n }\n : {}),\n });\n}\n\n/**\n * Contract target does not match config target.\n */\nexport function errorTargetMismatch(\n expected: string,\n actual: string,\n options?: {\n readonly why?: string;\n },\n): CliStructuredError {\n return new CliStructuredError('3003', 'Target mismatch', {\n domain: 'RUN',\n why:\n options?.why ??\n `Contract target does not match config target (expected: ${expected}, actual: ${actual})`,\n fix: 'Align contract target and config target',\n meta: { expected, actual },\n });\n}\n\n/**\n * Database marker is required but not found.\n * Used by commands that require a pre-existing marker as a precondition.\n */\nexport function errorMarkerRequired(options?: {\n readonly why?: string;\n readonly fix?: string;\n}): CliStructuredError {\n return new CliStructuredError('3010', 'Database must be signed first', {\n domain: 'RUN',\n why: options?.why ?? 'No database signature (marker) found',\n fix: options?.fix ?? 'Run `prisma-next db init` first to sign the database',\n });\n}\n\n/**\n * Schema verification found mismatches between the database and the contract.\n * The full verification tree is preserved in `meta.verificationResult`.\n */\nexport function errorSchemaVerificationFailed(options: {\n readonly summary: string;\n readonly verificationResult: VerifyDatabaseSchemaResult;\n readonly issues?: readonly SchemaIssue[];\n}): CliStructuredError {\n return new CliStructuredError('3004', options.summary, {\n domain: 'RUN',\n why: 'Database schema does not satisfy the contract',\n fix: 'Run `prisma-next db update` to reconcile, or adjust your contract to match the database',\n meta: {\n verificationResult: options.verificationResult,\n ...ifDefined('issues', options.issues),\n },\n });\n}\n\n/**\n * Migration runner failed during execution.\n */\nexport function errorRunnerFailed(\n summary: string,\n options?: {\n readonly why?: string;\n readonly fix?: string;\n readonly meta?: Record<string, unknown>;\n },\n): CliStructuredError {\n return new CliStructuredError('3020', summary, {\n domain: 'RUN',\n why: options?.why ?? 'Migration runner failed',\n fix: options?.fix ?? 'Inspect the reported conflict and reconcile schema drift',\n ...(options?.meta ? { meta: options.meta } : {}),\n });\n}\n\n/** Error code for destructive changes that require explicit confirmation. */\nexport const ERROR_CODE_DESTRUCTIVE_CHANGES = '3030';\n\n/**\n * Destructive operations require explicit confirmation via -y/--yes.\n */\nexport function errorDestructiveChanges(\n summary: string,\n options?: {\n readonly why?: string;\n readonly fix?: string;\n readonly meta?: Record<string, unknown>;\n },\n): CliStructuredError {\n return new CliStructuredError(ERROR_CODE_DESTRUCTIVE_CHANGES, summary, {\n domain: 'RUN',\n why: options?.why ?? 'Planned operations include destructive changes that require confirmation',\n fix: options?.fix ?? 'Re-run with `-y` to apply, or use `--dry-run` to preview first',\n ...(options?.meta ? { meta: options.meta } : {}),\n });\n}\n\n/**\n * Generic runtime error.\n */\nexport function errorRuntime(\n summary: string,\n options?: {\n readonly why?: string;\n readonly fix?: string;\n readonly meta?: Record<string, unknown>;\n },\n): CliStructuredError {\n return new CliStructuredError('3000', summary, {\n domain: 'RUN',\n ...(options?.why ? { why: options.why } : { why: 'Verification failed' }),\n ...(options?.fix ? { fix: options.fix } : { fix: 'Check contract and database state' }),\n ...(options?.meta ? { meta: options.meta } : {}),\n });\n}\n\n// ============================================================================\n// Generic Error\n// ============================================================================\n\n/**\n * Generic unexpected error.\n */\nexport function errorUnexpected(\n message: string,\n options?: {\n readonly why?: string;\n readonly fix?: string;\n },\n): CliStructuredError {\n return new CliStructuredError('4999', 'Unexpected error', {\n domain: 'CLI',\n why: options?.why ?? message,\n fix: options?.fix ?? 'Check the error message and try again',\n });\n}\n"],"mappings":";;;;;;;AAsCA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAMT,AAAS;CACT,AAAS;CAET,YACE,MACA,SACA,SASA;AACA,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,OAAO;AACZ,OAAK,SAAS,SAAS,UAAU;AACjC,OAAK,WAAW,SAAS,YAAY;AACrC,OAAK,MAAM,SAAS;AACpB,OAAK,MAAM,SAAS,QAAQ,SAAS,MAAM,SAAY,SAAS;AAChE,OAAK,QAAQ,SAAS,QAClB;GACE,MAAM,QAAQ,MAAM;GACpB,MAAM,QAAQ,MAAM;GACrB,GACD;AACJ,OAAK,OAAO,SAAS;AACrB,OAAK,UAAU,SAAS;;;;;CAM1B,aAA+B;AAE7B,SAAO;GACL,IAAI;GACJ,MAAM,GAHW,KAAK,WAAW,QAAQ,YAAY,YAG/B,KAAK;GAC3B,QAAQ,KAAK;GACb,UA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,SAAS,MAAM,EAAE,KAAK,QAAQ,KAAK,GAAG,EAAE,KAAK,qCAAqC;EACtF,GAAI,SAAS,OAAO,EAAE,MAAM,QAAQ,MAAM,GAAG,EAAE;EAChD,CAAC;;;;;AAUJ,SAAgB,gBACd,SACA,SAIoB;AACpB,QAAO,IAAI,mBAAmB,QAAQ,oBAAoB;EACxD,QAAQ;EACR,KAAK,SAAS,OAAO;EACrB,KAAK,SAAS,OAAO;EACtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/core-control-plane",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.89",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Control-plane migration/emission primitives and structured error utilities",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"arktype": "^2.1.26",
|
|
9
9
|
"prettier": "^3.3.3",
|
|
10
|
-
"@prisma-next/
|
|
11
|
-
"@prisma-next/
|
|
12
|
-
"@prisma-next/operations": "0.3.0-dev.
|
|
10
|
+
"@prisma-next/utils": "0.3.0-dev.89",
|
|
11
|
+
"@prisma-next/contract": "0.3.0-dev.89",
|
|
12
|
+
"@prisma-next/operations": "0.3.0-dev.89"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"tsdown": "0.18.4",
|
|
16
16
|
"typescript": "5.9.3",
|
|
17
17
|
"vitest": "4.0.17",
|
|
18
18
|
"@prisma-next/test-utils": "0.0.1",
|
|
19
|
-
"@prisma-next/
|
|
20
|
-
"@prisma-next/
|
|
19
|
+
"@prisma-next/tsconfig": "0.0.0",
|
|
20
|
+
"@prisma-next/tsdown": "0.0.0"
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
23
|
"dist",
|
package/src/errors.ts
CHANGED
|
@@ -38,7 +38,7 @@ export interface CliErrorConflict {
|
|
|
38
38
|
*/
|
|
39
39
|
export class CliStructuredError extends Error {
|
|
40
40
|
readonly code: string;
|
|
41
|
-
readonly domain: 'CLI' | '
|
|
41
|
+
readonly domain: 'CLI' | 'RUN';
|
|
42
42
|
readonly severity: 'error' | 'warn' | 'info';
|
|
43
43
|
readonly why: string | undefined;
|
|
44
44
|
readonly fix: string | undefined;
|
|
@@ -55,7 +55,7 @@ export class CliStructuredError extends Error {
|
|
|
55
55
|
code: string,
|
|
56
56
|
summary: string,
|
|
57
57
|
options?: {
|
|
58
|
-
readonly domain?: 'CLI' | '
|
|
58
|
+
readonly domain?: 'CLI' | 'RUN';
|
|
59
59
|
readonly severity?: 'error' | 'warn' | 'info';
|
|
60
60
|
readonly why?: string;
|
|
61
61
|
readonly fix?: string;
|
|
@@ -85,7 +85,7 @@ export class CliStructuredError extends Error {
|
|
|
85
85
|
* Converts this error to a CLI error envelope for output formatting.
|
|
86
86
|
*/
|
|
87
87
|
toEnvelope(): CliErrorEnvelope {
|
|
88
|
-
const codePrefix = this.domain === 'CLI' ? 'PN-CLI-' : 'PN-
|
|
88
|
+
const codePrefix = this.domain === 'CLI' ? 'PN-CLI-' : 'PN-RUN-';
|
|
89
89
|
return {
|
|
90
90
|
ok: false as const,
|
|
91
91
|
code: `${codePrefix}${this.code}`,
|
|
@@ -112,7 +112,7 @@ export class CliStructuredError extends Error {
|
|
|
112
112
|
return (
|
|
113
113
|
candidate.name === 'CliStructuredError' &&
|
|
114
114
|
typeof candidate.code === 'string' &&
|
|
115
|
-
(candidate.domain === 'CLI' || candidate.domain === '
|
|
115
|
+
(candidate.domain === 'CLI' || candidate.domain === 'RUN') &&
|
|
116
116
|
typeof candidate.toEnvelope === 'function'
|
|
117
117
|
);
|
|
118
118
|
}
|
|
@@ -356,7 +356,7 @@ export function errorConfigValidation(
|
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
// ============================================================================
|
|
359
|
-
// Runtime Errors (PN-
|
|
359
|
+
// Runtime Errors (PN-RUN-3000-3030)
|
|
360
360
|
// ============================================================================
|
|
361
361
|
|
|
362
362
|
/**
|
|
@@ -367,7 +367,7 @@ export function errorMarkerMissing(options?: {
|
|
|
367
367
|
readonly dbUrl?: string;
|
|
368
368
|
}): CliStructuredError {
|
|
369
369
|
return new CliStructuredError('3001', 'Database not signed', {
|
|
370
|
-
domain: '
|
|
370
|
+
domain: 'RUN',
|
|
371
371
|
why: options?.why ?? 'No database signature (marker) found',
|
|
372
372
|
fix: 'Run `prisma-next db sign --db <url>` to sign the database',
|
|
373
373
|
});
|
|
@@ -382,7 +382,7 @@ export function errorHashMismatch(options?: {
|
|
|
382
382
|
readonly actual?: string;
|
|
383
383
|
}): CliStructuredError {
|
|
384
384
|
return new CliStructuredError('3002', 'Hash mismatch', {
|
|
385
|
-
domain: '
|
|
385
|
+
domain: 'RUN',
|
|
386
386
|
why: options?.why ?? 'Contract hash does not match database marker',
|
|
387
387
|
fix: 'Migrate database or re-sign if intentional',
|
|
388
388
|
...(options?.expected || options?.actual
|
|
@@ -407,7 +407,7 @@ export function errorTargetMismatch(
|
|
|
407
407
|
},
|
|
408
408
|
): CliStructuredError {
|
|
409
409
|
return new CliStructuredError('3003', 'Target mismatch', {
|
|
410
|
-
domain: '
|
|
410
|
+
domain: 'RUN',
|
|
411
411
|
why:
|
|
412
412
|
options?.why ??
|
|
413
413
|
`Contract target does not match config target (expected: ${expected}, actual: ${actual})`,
|
|
@@ -425,7 +425,7 @@ export function errorMarkerRequired(options?: {
|
|
|
425
425
|
readonly fix?: string;
|
|
426
426
|
}): CliStructuredError {
|
|
427
427
|
return new CliStructuredError('3010', 'Database must be signed first', {
|
|
428
|
-
domain: '
|
|
428
|
+
domain: 'RUN',
|
|
429
429
|
why: options?.why ?? 'No database signature (marker) found',
|
|
430
430
|
fix: options?.fix ?? 'Run `prisma-next db init` first to sign the database',
|
|
431
431
|
});
|
|
@@ -441,7 +441,7 @@ export function errorSchemaVerificationFailed(options: {
|
|
|
441
441
|
readonly issues?: readonly SchemaIssue[];
|
|
442
442
|
}): CliStructuredError {
|
|
443
443
|
return new CliStructuredError('3004', options.summary, {
|
|
444
|
-
domain: '
|
|
444
|
+
domain: 'RUN',
|
|
445
445
|
why: 'Database schema does not satisfy the contract',
|
|
446
446
|
fix: 'Run `prisma-next db update` to reconcile, or adjust your contract to match the database',
|
|
447
447
|
meta: {
|
|
@@ -463,7 +463,7 @@ export function errorRunnerFailed(
|
|
|
463
463
|
},
|
|
464
464
|
): CliStructuredError {
|
|
465
465
|
return new CliStructuredError('3020', summary, {
|
|
466
|
-
domain: '
|
|
466
|
+
domain: 'RUN',
|
|
467
467
|
why: options?.why ?? 'Migration runner failed',
|
|
468
468
|
fix: options?.fix ?? 'Inspect the reported conflict and reconcile schema drift',
|
|
469
469
|
...(options?.meta ? { meta: options.meta } : {}),
|
|
@@ -485,7 +485,7 @@ export function errorDestructiveChanges(
|
|
|
485
485
|
},
|
|
486
486
|
): CliStructuredError {
|
|
487
487
|
return new CliStructuredError(ERROR_CODE_DESTRUCTIVE_CHANGES, summary, {
|
|
488
|
-
domain: '
|
|
488
|
+
domain: 'RUN',
|
|
489
489
|
why: options?.why ?? 'Planned operations include destructive changes that require confirmation',
|
|
490
490
|
fix: options?.fix ?? 'Re-run with `-y` to apply, or use `--dry-run` to preview first',
|
|
491
491
|
...(options?.meta ? { meta: options.meta } : {}),
|
|
@@ -504,7 +504,7 @@ export function errorRuntime(
|
|
|
504
504
|
},
|
|
505
505
|
): CliStructuredError {
|
|
506
506
|
return new CliStructuredError('3000', summary, {
|
|
507
|
-
domain: '
|
|
507
|
+
domain: 'RUN',
|
|
508
508
|
...(options?.why ? { why: options.why } : { why: 'Verification failed' }),
|
|
509
509
|
...(options?.fix ? { fix: options.fix } : { fix: 'Check contract and database state' }),
|
|
510
510
|
...(options?.meta ? { meta: options.meta } : {}),
|