@prisma-next/errors 0.0.1
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/LICENSE +201 -0
- package/README.md +36 -0
- package/package.json +45 -0
- package/src/control.ts +372 -0
- package/src/execution.ts +159 -0
- package/src/exports/control.ts +18 -0
- package/src/exports/execution.ts +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2026] [Prisma Data, Inc]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @prisma-next/errors
|
|
2
|
+
|
|
3
|
+
Structured error types and factories for CLI and runtime error reporting.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides `CliStructuredError` (the shared error class) and factory functions for creating structured errors with error codes, fix suggestions, and machine-readable metadata. Errors are split across two entry points by domain:
|
|
8
|
+
|
|
9
|
+
- **`./control`** — CLI errors (`PN-CLI-4xxx`): config validation, file resolution, migration planning
|
|
10
|
+
- **`./execution`** — Runtime errors (`PN-RUN-3xxx`): contract verification, hash mismatch, database signing
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { CliStructuredError, errorConfigFileNotFound } from '@prisma-next/errors/control';
|
|
16
|
+
import { errorHashMismatch } from '@prisma-next/errors/execution';
|
|
17
|
+
|
|
18
|
+
// Create a CLI error
|
|
19
|
+
throw errorConfigFileNotFound('/path/to/config.ts');
|
|
20
|
+
|
|
21
|
+
// Create a runtime error
|
|
22
|
+
throw errorHashMismatch({ expected: 'abc123', actual: 'def456' });
|
|
23
|
+
|
|
24
|
+
// Type-guard check
|
|
25
|
+
if (CliStructuredError.is(caught)) {
|
|
26
|
+
const envelope = caught.toEnvelope();
|
|
27
|
+
// { ok: false, code: 'PN-CLI-4001', domain: 'CLI', summary: '...', ... }
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Entry points
|
|
32
|
+
|
|
33
|
+
| Entry point | Domain | Code range | Contents |
|
|
34
|
+
|---|---|---|---|
|
|
35
|
+
| `./control` | CLI | `PN-CLI-4xxx` | `CliStructuredError` class, `CliErrorEnvelope`/`CliErrorConflict` types, 14 CLI factory functions, `errorUnexpected` |
|
|
36
|
+
| `./execution` | RUN | `PN-RUN-3xxx` | 8 runtime factory functions, `ERROR_CODE_DESTRUCTIVE_CHANGES` constant |
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prisma-next/errors",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"description": "Structured error types for Prisma Next control and execution planes",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@prisma-next/framework-components": "0.0.1",
|
|
9
|
+
"@prisma-next/utils": "0.0.1"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"tsdown": "0.18.4",
|
|
13
|
+
"typescript": "5.9.3",
|
|
14
|
+
"vitest": "4.0.17",
|
|
15
|
+
"@prisma-next/tsdown": "0.0.0",
|
|
16
|
+
"@prisma-next/tsconfig": "0.0.0"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"src"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=20"
|
|
24
|
+
},
|
|
25
|
+
"exports": {
|
|
26
|
+
"./control": "./dist/control.mjs",
|
|
27
|
+
"./execution": "./dist/execution.mjs",
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/prisma/prisma-next.git",
|
|
33
|
+
"directory": "packages/1-framework/1-core/errors"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsdown",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:coverage": "vitest run --coverage",
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"lint": "biome check . --error-on-warnings",
|
|
41
|
+
"lint:fix": "biome check --write .",
|
|
42
|
+
"lint:fix:unsafe": "biome check --write --unsafe .",
|
|
43
|
+
"clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/control.ts
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI error envelope for output formatting.
|
|
3
|
+
* This is the serialized form of a CliStructuredError.
|
|
4
|
+
*/
|
|
5
|
+
export interface CliErrorEnvelope {
|
|
6
|
+
readonly ok: false;
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly domain: string;
|
|
9
|
+
readonly severity: 'error' | 'warn' | 'info';
|
|
10
|
+
readonly summary: string;
|
|
11
|
+
readonly why: string | undefined;
|
|
12
|
+
readonly fix: string | undefined;
|
|
13
|
+
readonly where:
|
|
14
|
+
| {
|
|
15
|
+
readonly path: string | undefined;
|
|
16
|
+
readonly line: number | undefined;
|
|
17
|
+
}
|
|
18
|
+
| undefined;
|
|
19
|
+
readonly meta: Record<string, unknown> | undefined;
|
|
20
|
+
readonly docsUrl: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Minimal conflict data structure expected by CLI output.
|
|
25
|
+
*/
|
|
26
|
+
export interface CliErrorConflict {
|
|
27
|
+
readonly kind: string;
|
|
28
|
+
readonly summary: string;
|
|
29
|
+
readonly why?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Structured CLI error that contains all information needed for error envelopes.
|
|
34
|
+
* Call sites throw these errors with full context.
|
|
35
|
+
*/
|
|
36
|
+
export class CliStructuredError extends Error {
|
|
37
|
+
readonly code: string;
|
|
38
|
+
readonly domain: 'CLI' | 'RUN';
|
|
39
|
+
readonly severity: 'error' | 'warn' | 'info';
|
|
40
|
+
readonly why: string | undefined;
|
|
41
|
+
readonly fix: string | undefined;
|
|
42
|
+
readonly where:
|
|
43
|
+
| {
|
|
44
|
+
readonly path: string | undefined;
|
|
45
|
+
readonly line: number | undefined;
|
|
46
|
+
}
|
|
47
|
+
| undefined;
|
|
48
|
+
readonly meta: Record<string, unknown> | undefined;
|
|
49
|
+
readonly docsUrl: string | undefined;
|
|
50
|
+
|
|
51
|
+
constructor(
|
|
52
|
+
code: string,
|
|
53
|
+
summary: string,
|
|
54
|
+
options?: {
|
|
55
|
+
readonly domain?: 'CLI' | 'RUN';
|
|
56
|
+
readonly severity?: 'error' | 'warn' | 'info';
|
|
57
|
+
readonly why?: string;
|
|
58
|
+
readonly fix?: string;
|
|
59
|
+
readonly where?: { readonly path?: string; readonly line?: number };
|
|
60
|
+
readonly meta?: Record<string, unknown>;
|
|
61
|
+
readonly docsUrl?: string;
|
|
62
|
+
},
|
|
63
|
+
) {
|
|
64
|
+
super(summary);
|
|
65
|
+
this.name = 'CliStructuredError';
|
|
66
|
+
this.code = code;
|
|
67
|
+
this.domain = options?.domain ?? 'CLI';
|
|
68
|
+
this.severity = options?.severity ?? 'error';
|
|
69
|
+
this.why = options?.why;
|
|
70
|
+
this.fix = options?.fix === options?.why ? undefined : options?.fix;
|
|
71
|
+
this.where = options?.where
|
|
72
|
+
? {
|
|
73
|
+
path: options.where.path,
|
|
74
|
+
line: options.where.line,
|
|
75
|
+
}
|
|
76
|
+
: undefined;
|
|
77
|
+
this.meta = options?.meta;
|
|
78
|
+
this.docsUrl = options?.docsUrl;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Converts this error to a CLI error envelope for output formatting.
|
|
83
|
+
*/
|
|
84
|
+
toEnvelope(): CliErrorEnvelope {
|
|
85
|
+
const codePrefix = this.domain === 'CLI' ? 'PN-CLI-' : 'PN-RUN-';
|
|
86
|
+
return {
|
|
87
|
+
ok: false as const,
|
|
88
|
+
code: `${codePrefix}${this.code}`,
|
|
89
|
+
domain: this.domain,
|
|
90
|
+
severity: this.severity,
|
|
91
|
+
summary: this.message,
|
|
92
|
+
why: this.why,
|
|
93
|
+
fix: this.fix,
|
|
94
|
+
where: this.where,
|
|
95
|
+
meta: this.meta,
|
|
96
|
+
docsUrl: this.docsUrl,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Type guard to check if an error is a CliStructuredError.
|
|
102
|
+
* Uses duck-typing to work across module boundaries where instanceof may fail.
|
|
103
|
+
*/
|
|
104
|
+
static is(error: unknown): error is CliStructuredError {
|
|
105
|
+
if (!(error instanceof Error)) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
const candidate = error as CliStructuredError;
|
|
109
|
+
return (
|
|
110
|
+
candidate.name === 'CliStructuredError' &&
|
|
111
|
+
typeof candidate.code === 'string' &&
|
|
112
|
+
(candidate.domain === 'CLI' || candidate.domain === 'RUN') &&
|
|
113
|
+
typeof candidate.toEnvelope === 'function'
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ============================================================================
|
|
119
|
+
// Config Errors (PN-CLI-4001-4007)
|
|
120
|
+
// ============================================================================
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Config file not found or missing.
|
|
124
|
+
*/
|
|
125
|
+
export function errorConfigFileNotFound(
|
|
126
|
+
configPath?: string,
|
|
127
|
+
options?: {
|
|
128
|
+
readonly why?: string;
|
|
129
|
+
},
|
|
130
|
+
): CliStructuredError {
|
|
131
|
+
return new CliStructuredError('4001', 'Config file not found', {
|
|
132
|
+
domain: 'CLI',
|
|
133
|
+
...(options?.why ? { why: options.why } : { why: 'Config file not found' }),
|
|
134
|
+
fix: "Run 'prisma-next init' to create a config file",
|
|
135
|
+
docsUrl: 'https://prisma-next.dev/docs/cli/config',
|
|
136
|
+
...(configPath ? { where: { path: configPath } } : {}),
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Contract configuration missing from config.
|
|
142
|
+
*/
|
|
143
|
+
export function errorContractConfigMissing(options?: {
|
|
144
|
+
readonly why?: string;
|
|
145
|
+
}): CliStructuredError {
|
|
146
|
+
return new CliStructuredError('4002', 'Contract configuration missing', {
|
|
147
|
+
domain: 'CLI',
|
|
148
|
+
why: options?.why ?? 'The contract configuration is required for emit',
|
|
149
|
+
fix: 'Add contract configuration to your prisma-next.config.ts',
|
|
150
|
+
docsUrl: 'https://prisma-next.dev/docs/cli/contract-emit',
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Contract validation failed.
|
|
156
|
+
*/
|
|
157
|
+
export function errorContractValidationFailed(
|
|
158
|
+
reason: string,
|
|
159
|
+
options?: {
|
|
160
|
+
readonly where?: { readonly path?: string; readonly line?: number };
|
|
161
|
+
},
|
|
162
|
+
): CliStructuredError {
|
|
163
|
+
return new CliStructuredError('4003', 'Contract validation failed', {
|
|
164
|
+
domain: 'CLI',
|
|
165
|
+
why: reason,
|
|
166
|
+
fix: 'Re-run `prisma-next contract emit`, or fix the contract file and try again',
|
|
167
|
+
docsUrl: 'https://prisma-next.dev/docs/contracts',
|
|
168
|
+
...(options?.where ? { where: options.where } : {}),
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* File not found.
|
|
174
|
+
*/
|
|
175
|
+
export function errorFileNotFound(
|
|
176
|
+
filePath: string,
|
|
177
|
+
options?: {
|
|
178
|
+
readonly why?: string;
|
|
179
|
+
readonly fix?: string;
|
|
180
|
+
readonly docsUrl?: string;
|
|
181
|
+
},
|
|
182
|
+
): CliStructuredError {
|
|
183
|
+
return new CliStructuredError('4004', 'File not found', {
|
|
184
|
+
domain: 'CLI',
|
|
185
|
+
why: options?.why ?? `File not found: ${filePath}`,
|
|
186
|
+
fix: options?.fix ?? 'Check that the file path is correct',
|
|
187
|
+
where: { path: filePath },
|
|
188
|
+
...(options?.docsUrl ? { docsUrl: options.docsUrl } : {}),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Database connection is required but not provided.
|
|
194
|
+
*/
|
|
195
|
+
export function errorDatabaseConnectionRequired(options?: {
|
|
196
|
+
readonly why?: string;
|
|
197
|
+
readonly commandName?: string;
|
|
198
|
+
readonly retryCommand?: string;
|
|
199
|
+
}): CliStructuredError {
|
|
200
|
+
const runHint = options?.retryCommand
|
|
201
|
+
? `Run \`${options.retryCommand}\``
|
|
202
|
+
: options?.commandName
|
|
203
|
+
? `Run \`prisma-next ${options.commandName} --db <url>\``
|
|
204
|
+
: 'Provide `--db <url>`';
|
|
205
|
+
return new CliStructuredError('4005', 'Database connection is required', {
|
|
206
|
+
domain: 'CLI',
|
|
207
|
+
why: options?.why ?? 'Database connection is required for this command',
|
|
208
|
+
fix: `${runHint}, or set \`db: { connection: "postgres://…" }\` in prisma-next.config.ts`,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Query runner factory is required but not provided in config.
|
|
214
|
+
*/
|
|
215
|
+
export function errorQueryRunnerFactoryRequired(options?: {
|
|
216
|
+
readonly why?: string;
|
|
217
|
+
}): CliStructuredError {
|
|
218
|
+
return new CliStructuredError('4006', 'Query runner factory is required', {
|
|
219
|
+
domain: 'CLI',
|
|
220
|
+
why: options?.why ?? 'Config.db.queryRunnerFactory is required for db verify',
|
|
221
|
+
fix: 'Add db.queryRunnerFactory to prisma-next.config.ts',
|
|
222
|
+
docsUrl: 'https://prisma-next.dev/docs/cli/db-verify',
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Family verify.readMarker is required but not provided.
|
|
228
|
+
*/
|
|
229
|
+
export function errorFamilyReadMarkerSqlRequired(options?: {
|
|
230
|
+
readonly why?: string;
|
|
231
|
+
}): CliStructuredError {
|
|
232
|
+
return new CliStructuredError('4007', 'Family readMarker() is required', {
|
|
233
|
+
domain: 'CLI',
|
|
234
|
+
why: options?.why ?? 'Family verify.readMarker is required for db verify',
|
|
235
|
+
fix: 'Ensure family.verify.readMarker() is exported by your family package',
|
|
236
|
+
docsUrl: 'https://prisma-next.dev/docs/cli/db-verify',
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* JSON output format not supported.
|
|
242
|
+
*/
|
|
243
|
+
export function errorJsonFormatNotSupported(options: {
|
|
244
|
+
readonly command: string;
|
|
245
|
+
readonly format: string;
|
|
246
|
+
readonly supportedFormats: readonly string[];
|
|
247
|
+
}): CliStructuredError {
|
|
248
|
+
return new CliStructuredError('4008', 'Unsupported JSON format', {
|
|
249
|
+
domain: 'CLI',
|
|
250
|
+
why: `The ${options.command} command does not support --json ${options.format}`,
|
|
251
|
+
fix: `Use --json ${options.supportedFormats.join(' or ')}, or omit --json for human output`,
|
|
252
|
+
meta: {
|
|
253
|
+
command: options.command,
|
|
254
|
+
format: options.format,
|
|
255
|
+
supportedFormats: options.supportedFormats,
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Driver is required for DB-connected commands but not provided.
|
|
262
|
+
*/
|
|
263
|
+
export function errorDriverRequired(options?: { readonly why?: string }): CliStructuredError {
|
|
264
|
+
return new CliStructuredError('4010', 'Driver is required for DB-connected commands', {
|
|
265
|
+
domain: 'CLI',
|
|
266
|
+
why: options?.why ?? 'Config.driver is required for DB-connected commands',
|
|
267
|
+
fix: 'Add a control-plane driver to prisma-next.config.ts (e.g. import a driver descriptor and set `driver: postgresDriver`)',
|
|
268
|
+
docsUrl: 'https://prisma-next.dev/docs/cli/config',
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Contract requires extension packs that are not provided by config descriptors.
|
|
274
|
+
*/
|
|
275
|
+
export function errorContractMissingExtensionPacks(options: {
|
|
276
|
+
readonly missingExtensionPacks: readonly string[];
|
|
277
|
+
readonly providedComponentIds: readonly string[];
|
|
278
|
+
}): CliStructuredError {
|
|
279
|
+
const missing = [...options.missingExtensionPacks].sort();
|
|
280
|
+
return new CliStructuredError('4011', 'Missing extension packs in config', {
|
|
281
|
+
domain: 'CLI',
|
|
282
|
+
why:
|
|
283
|
+
missing.length === 1
|
|
284
|
+
? `Contract requires extension pack '${missing[0]}', but CLI config does not provide a matching descriptor.`
|
|
285
|
+
: `Contract requires extension packs ${missing.map((p) => `'${p}'`).join(', ')}, but CLI config does not provide matching descriptors.`,
|
|
286
|
+
fix: 'Add the missing extension descriptors to `extensions` in prisma-next.config.ts',
|
|
287
|
+
docsUrl: 'https://prisma-next.dev/docs/cli/config',
|
|
288
|
+
meta: {
|
|
289
|
+
missingExtensionPacks: missing,
|
|
290
|
+
providedComponentIds: [...options.providedComponentIds].sort(),
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Migration planning failed due to conflicts.
|
|
297
|
+
*/
|
|
298
|
+
export function errorMigrationPlanningFailed(options: {
|
|
299
|
+
readonly conflicts: readonly CliErrorConflict[];
|
|
300
|
+
readonly why?: string;
|
|
301
|
+
}): CliStructuredError {
|
|
302
|
+
const conflictSummaries = options.conflicts.map((c) => c.summary);
|
|
303
|
+
const computedWhy = options.why ?? conflictSummaries.join('\n');
|
|
304
|
+
|
|
305
|
+
const conflictFixes = options.conflicts
|
|
306
|
+
.map((c) => c.why)
|
|
307
|
+
.filter((why): why is string => typeof why === 'string');
|
|
308
|
+
const computedFix =
|
|
309
|
+
conflictFixes.length > 0
|
|
310
|
+
? conflictFixes.join('\n')
|
|
311
|
+
: 'Use `db verify --schema-only` to inspect conflicts, or ensure the database is empty';
|
|
312
|
+
|
|
313
|
+
return new CliStructuredError('4020', 'Migration planning failed', {
|
|
314
|
+
domain: 'CLI',
|
|
315
|
+
why: computedWhy,
|
|
316
|
+
fix: computedFix,
|
|
317
|
+
meta: { conflicts: options.conflicts },
|
|
318
|
+
docsUrl: 'https://prisma-next.dev/docs/cli/db-init',
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Target does not support migrations (missing createPlanner/createRunner).
|
|
324
|
+
*/
|
|
325
|
+
export function errorTargetMigrationNotSupported(options?: {
|
|
326
|
+
readonly why?: string;
|
|
327
|
+
}): CliStructuredError {
|
|
328
|
+
return new CliStructuredError('4021', 'Target does not support migrations', {
|
|
329
|
+
domain: 'CLI',
|
|
330
|
+
why: options?.why ?? 'The configured target does not provide migration planner/runner',
|
|
331
|
+
fix: 'Select a target that provides migrations (it must export `target.migrations` for db init)',
|
|
332
|
+
docsUrl: 'https://prisma-next.dev/docs/cli/db-init',
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Config validation error (missing required fields).
|
|
338
|
+
*/
|
|
339
|
+
export function errorConfigValidation(
|
|
340
|
+
field: string,
|
|
341
|
+
options?: {
|
|
342
|
+
readonly why?: string;
|
|
343
|
+
},
|
|
344
|
+
): CliStructuredError {
|
|
345
|
+
return new CliStructuredError('4009', 'Config validation error', {
|
|
346
|
+
domain: 'CLI',
|
|
347
|
+
why: options?.why ?? `Config must have a "${field}" field`,
|
|
348
|
+
fix: 'Check your prisma-next.config.ts and ensure all required fields are provided',
|
|
349
|
+
docsUrl: 'https://prisma-next.dev/docs/cli/config',
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// ============================================================================
|
|
354
|
+
// Generic Error
|
|
355
|
+
// ============================================================================
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Generic unexpected error.
|
|
359
|
+
*/
|
|
360
|
+
export function errorUnexpected(
|
|
361
|
+
message: string,
|
|
362
|
+
options?: {
|
|
363
|
+
readonly why?: string;
|
|
364
|
+
readonly fix?: string;
|
|
365
|
+
},
|
|
366
|
+
): CliStructuredError {
|
|
367
|
+
return new CliStructuredError('4999', 'Unexpected error', {
|
|
368
|
+
domain: 'CLI',
|
|
369
|
+
why: options?.why ?? message,
|
|
370
|
+
fix: options?.fix ?? 'Check the error message and try again',
|
|
371
|
+
});
|
|
372
|
+
}
|
package/src/execution.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SchemaIssue,
|
|
3
|
+
VerifyDatabaseSchemaResult,
|
|
4
|
+
} from '@prisma-next/framework-components/control';
|
|
5
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
6
|
+
import { CliStructuredError } from './control';
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Runtime Errors (PN-RUN-3000-3030)
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Contract marker not found in database.
|
|
14
|
+
*/
|
|
15
|
+
export function errorMarkerMissing(options?: { readonly why?: string }): CliStructuredError {
|
|
16
|
+
return new CliStructuredError('3001', 'Database not signed', {
|
|
17
|
+
domain: 'RUN',
|
|
18
|
+
why: options?.why ?? 'No database signature (marker) found',
|
|
19
|
+
fix: 'Run `prisma-next db sign --db <url>` to sign the database',
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Contract hash does not match database marker.
|
|
25
|
+
*/
|
|
26
|
+
export function errorHashMismatch(options?: {
|
|
27
|
+
readonly why?: string;
|
|
28
|
+
readonly expected?: string;
|
|
29
|
+
readonly actual?: string;
|
|
30
|
+
}): CliStructuredError {
|
|
31
|
+
return new CliStructuredError('3002', 'Hash mismatch', {
|
|
32
|
+
domain: 'RUN',
|
|
33
|
+
why: options?.why ?? 'Contract hash does not match database marker',
|
|
34
|
+
fix: 'Migrate database or re-sign if intentional',
|
|
35
|
+
...(options?.expected !== undefined || options?.actual !== undefined
|
|
36
|
+
? {
|
|
37
|
+
meta: {
|
|
38
|
+
...ifDefined('expected', options?.expected),
|
|
39
|
+
...ifDefined('actual', options?.actual),
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
: {}),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Contract target does not match config target.
|
|
48
|
+
*/
|
|
49
|
+
export function errorTargetMismatch(
|
|
50
|
+
expected: string,
|
|
51
|
+
actual: string,
|
|
52
|
+
options?: {
|
|
53
|
+
readonly why?: string;
|
|
54
|
+
},
|
|
55
|
+
): CliStructuredError {
|
|
56
|
+
return new CliStructuredError('3003', 'Target mismatch', {
|
|
57
|
+
domain: 'RUN',
|
|
58
|
+
why:
|
|
59
|
+
options?.why ??
|
|
60
|
+
`Contract target does not match config target (expected: ${expected}, actual: ${actual})`,
|
|
61
|
+
fix: 'Align contract target and config target',
|
|
62
|
+
meta: { expected, actual },
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Database marker is required but not found.
|
|
68
|
+
* Used by commands that require a pre-existing marker as a precondition.
|
|
69
|
+
*/
|
|
70
|
+
export function errorMarkerRequired(options?: {
|
|
71
|
+
readonly why?: string;
|
|
72
|
+
readonly fix?: string;
|
|
73
|
+
}): CliStructuredError {
|
|
74
|
+
return new CliStructuredError('3010', 'Database must be signed first', {
|
|
75
|
+
domain: 'RUN',
|
|
76
|
+
why: options?.why ?? 'No database signature (marker) found',
|
|
77
|
+
fix: options?.fix ?? 'Run `prisma-next db init` first to sign the database',
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Schema verification found mismatches between the database and the contract.
|
|
83
|
+
* The full verification tree is preserved in `meta.verificationResult`.
|
|
84
|
+
*/
|
|
85
|
+
export function errorSchemaVerificationFailed(options: {
|
|
86
|
+
readonly summary: string;
|
|
87
|
+
readonly verificationResult: VerifyDatabaseSchemaResult;
|
|
88
|
+
readonly issues?: readonly SchemaIssue[];
|
|
89
|
+
}): CliStructuredError {
|
|
90
|
+
return new CliStructuredError('3004', options.summary, {
|
|
91
|
+
domain: 'RUN',
|
|
92
|
+
why: 'Database schema does not satisfy the contract',
|
|
93
|
+
fix: 'Run `prisma-next db update` to reconcile, or adjust your contract to match the database',
|
|
94
|
+
meta: {
|
|
95
|
+
verificationResult: options.verificationResult,
|
|
96
|
+
...ifDefined('issues', options.issues),
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Migration runner failed during execution.
|
|
103
|
+
*/
|
|
104
|
+
export function errorRunnerFailed(
|
|
105
|
+
summary: string,
|
|
106
|
+
options?: {
|
|
107
|
+
readonly why?: string;
|
|
108
|
+
readonly fix?: string;
|
|
109
|
+
readonly meta?: Record<string, unknown>;
|
|
110
|
+
},
|
|
111
|
+
): CliStructuredError {
|
|
112
|
+
return new CliStructuredError('3020', summary, {
|
|
113
|
+
domain: 'RUN',
|
|
114
|
+
why: options?.why ?? 'Migration runner failed',
|
|
115
|
+
fix: options?.fix ?? 'Inspect the reported conflict and reconcile schema drift',
|
|
116
|
+
...(options?.meta ? { meta: options.meta } : {}),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Error code for destructive changes that require explicit confirmation. */
|
|
121
|
+
export const ERROR_CODE_DESTRUCTIVE_CHANGES = '3030';
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Destructive operations require explicit confirmation via -y/--yes.
|
|
125
|
+
*/
|
|
126
|
+
export function errorDestructiveChanges(
|
|
127
|
+
summary: string,
|
|
128
|
+
options?: {
|
|
129
|
+
readonly why?: string;
|
|
130
|
+
readonly fix?: string;
|
|
131
|
+
readonly meta?: Record<string, unknown>;
|
|
132
|
+
},
|
|
133
|
+
): CliStructuredError {
|
|
134
|
+
return new CliStructuredError(ERROR_CODE_DESTRUCTIVE_CHANGES, summary, {
|
|
135
|
+
domain: 'RUN',
|
|
136
|
+
why: options?.why ?? 'Planned operations include destructive changes that require confirmation',
|
|
137
|
+
fix: options?.fix ?? 'Re-run with `-y` to apply, or use `--dry-run` to preview first',
|
|
138
|
+
...(options?.meta ? { meta: options.meta } : {}),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Generic runtime error.
|
|
144
|
+
*/
|
|
145
|
+
export function errorRuntime(
|
|
146
|
+
summary: string,
|
|
147
|
+
options?: {
|
|
148
|
+
readonly why?: string;
|
|
149
|
+
readonly fix?: string;
|
|
150
|
+
readonly meta?: Record<string, unknown>;
|
|
151
|
+
},
|
|
152
|
+
): CliStructuredError {
|
|
153
|
+
return new CliStructuredError('3000', summary, {
|
|
154
|
+
domain: 'RUN',
|
|
155
|
+
...(options?.why ? { why: options.why } : { why: 'Verification failed' }),
|
|
156
|
+
...(options?.fix ? { fix: options.fix } : { fix: 'Check contract and database state' }),
|
|
157
|
+
...(options?.meta ? { meta: options.meta } : {}),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type { CliErrorConflict, CliErrorEnvelope } from '../control';
|
|
2
|
+
export {
|
|
3
|
+
CliStructuredError,
|
|
4
|
+
errorConfigFileNotFound,
|
|
5
|
+
errorConfigValidation,
|
|
6
|
+
errorContractConfigMissing,
|
|
7
|
+
errorContractMissingExtensionPacks,
|
|
8
|
+
errorContractValidationFailed,
|
|
9
|
+
errorDatabaseConnectionRequired,
|
|
10
|
+
errorDriverRequired,
|
|
11
|
+
errorFamilyReadMarkerSqlRequired,
|
|
12
|
+
errorFileNotFound,
|
|
13
|
+
errorJsonFormatNotSupported,
|
|
14
|
+
errorMigrationPlanningFailed,
|
|
15
|
+
errorQueryRunnerFactoryRequired,
|
|
16
|
+
errorTargetMigrationNotSupported,
|
|
17
|
+
errorUnexpected,
|
|
18
|
+
} from '../control';
|