Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/reference/error-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ The config file's `$prismaConfig` marker declares a version other than the one t

### CLI.CONSENT_REQUIRED

A consent prompt was reached under `--yes` or in a non-interactive session. Consent has no default answer and `--yes` does not grant it, so there is nothing for the run to assume. When the consent declares a token, the message and next action say to pass `--confirm <token>`, and the token travels in meta; without a token, the only path is running the command interactively. Meta: `consentToken` (only when the consent declares a token).
A consent prompt was reached under `--yes` or in a non-interactive session. Consent has no default answer and `--yes` does not grant it, so there is nothing for the run to assume. The summary says the command requires explicit consent and did not get it (under `--yes`, that `--yes` does not give it), and `why` carries the consent's question. When the consent declares a token, the next action says to pass `--confirm <token>`, and the token travels in meta; without a token, the only path is running the command interactively. Meta: `consentToken` (only when the consent declares a token).

A statement prompt (`ctx.prompt.statement` or `ctx.prompt.statements`) raises the same code when no statement flag on the command line answers it. One error lists every question still unanswered: the summary says the command requires explicit consent and did not get it (under `--yes`, that `--yes` does not give it), `why` carries the questions, and the next actions give one flag to pass per verb, such as `--delete Legacy` or `--rename 'Legacy:<new name>'`. `why` also lists every given statement flag that names none of the questions' subjects, and any `--confirm` token, which answers no statement, so a misspelled flag is reported before anyone answers a prompt. Meta: `unanswered` (a list of `{ subject, verbs }`), plus `subject` and `verbs` when exactly one question is unanswered; `unmatched` (a list of `{ verb, values }`) and `confirm` (the tokens) when any.
A statement prompt (`ctx.prompt.statement` or `ctx.prompt.statements`) raises the same code when no statement flag on the command line answers it. One error lists every question still unanswered: the summary is the same sentence, `why` carries the questions, and the next actions give one flag to pass per verb, such as `--delete Legacy` or `--rename 'Legacy:<new name>'`. `why` also lists every given statement flag that names none of the questions' subjects, and any `--confirm` token, which answers no statement, so a misspelled flag is reported before anyone answers a prompt. Meta: `unanswered` (a list of `{ subject, verbs }`), plus `subject` and `verbs` when exactly one question is unanswered; `unmatched` (a list of `{ verb, values }`) and `confirm` (the tokens) when any.

### CLI.CONSENT_UNUSED

Expand Down
2 changes: 1 addition & 1 deletion packages/cli-engine/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prisma/cli-engine",
"version": "0.10.2",
"version": "0.10.3",
"description": "The execution engine of the unified Prisma CLI.",
"type": "module",
"exports": {
Expand Down
59 changes: 31 additions & 28 deletions packages/cli-engine/src/execution/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ function statementUnavailable<V extends string>(
subjects: readonly string[],
state: RunState,
): CliStructuredError {
const summary = state.yes
? "This command requires explicit consent, and --yes does not give it."
: "This command requires explicit consent, but it was not provided.";
const summary = consentMissing(state);
const listed = unanswered.map(({ subject, verbs }) => ({ subject, verbs }));
const unmatched = state.statementValues
.filter(
Expand Down Expand Up @@ -441,38 +439,43 @@ function answerWithoutAsking<T>(
return fallback;
}

function consentMissing(state: RunState): string {
return state.yes
? "This command requires explicit consent, and --yes does not give it."
: "This command requires explicit consent, but it was not provided.";
}

function consentUnavailable(
question: string,
state: RunState,
token: string | undefined,
): CliStructuredError {
const situation = state.yes
? `"${question}" requires explicit consent, which --yes cannot grant.`
: `"${question}" requires explicit consent, and the session is not interactive.`;
if (token === undefined) {
return new CliStructuredError("CLI.CONSENT_REQUIRED", situation, {
nextActions: [
{
kind: "user-choice",
label:
"Run the command interactively. Consent can only be granted outside an interactive terminal when the command declares a consent token.",
},
],
});
return new CliStructuredError(
"CLI.CONSENT_REQUIRED",
consentMissing(state),
{
why: question,
nextActions: [
{
kind: "user-choice",
label:
"Run the command interactively. Consent can only be granted outside an interactive terminal when the command declares a consent token.",
},
],
},
);
}
return new CliStructuredError(
"CLI.CONSENT_REQUIRED",
`${situation} Grant it by passing --confirm ${token}.`,
{
nextActions: [
{
kind: "user-choice",
label: `Run the command interactively and type ${token}, or pass --confirm ${token}.`,
},
],
meta: { consentToken: token },
},
);
return new CliStructuredError("CLI.CONSENT_REQUIRED", consentMissing(state), {
why: question,
nextActions: [
{
kind: "user-choice",
label: `Run the command interactively and type ${token}, or pass --confirm ${token}.`,
},
],
meta: { consentToken: token },
});
}

function promptInvalid(question: string, raw: string): CliStructuredError {
Expand Down
38 changes: 33 additions & 5 deletions packages/cli-engine/tests/interaction-affordances.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,19 @@ describe("consent tokens", () => {
]);

expect(result.exitCode).toBe(2);
expect(errorOf(result)?.code).toBe("CLI.CONSENT_REQUIRED");
expect(errorOf(result)?.summary).toContain("--confirm prod-db");
expect(errorOf(result)).toMatchObject({
code: "CLI.CONSENT_REQUIRED",
summary:
"This command requires explicit consent, but it was not provided.",
why: "Delete the production database?",
nextActions: [
{
label:
"Run the command interactively and type prod-db, or pass --confirm prod-db.",
},
],
meta: { consentToken: "prod-db" },
});
});

test("no --confirm at all halts the same way", async () => {
Expand All @@ -179,7 +190,12 @@ describe("consent tokens", () => {
INTERACTIVE,
);
expect(withoutConfirm.exitCode).toBe(2);
expect(errorOf(withoutConfirm)?.summary).toContain("--yes cannot grant");
expect(errorOf(withoutConfirm)).toMatchObject({
summary:
"This command requires explicit consent, and --yes does not give it.",
why: "Delete the production database?",
meta: { consentToken: "prod-db" },
});

const withConfirm = await cli.run(
["probe", "--yes", "--confirm", "prod-db"],
Expand Down Expand Up @@ -234,8 +250,20 @@ describe("consent tokens", () => {
"Delete everything?",
]);
expect(confirmed.exitCode).toBe(2);
expect(errorOf(confirmed)?.code).toBe("CLI.CONSENT_REQUIRED");
expect(errorOf(confirmed)?.summary).not.toContain("--confirm");
expect(errorOf(confirmed)).toEqual({
code: "CLI.CONSENT_REQUIRED",
severity: "error",
summary:
"This command requires explicit consent, but it was not provided.",
why: "Delete everything?",
nextActions: [
{
kind: "user-choice",
label:
"Run the command interactively. Consent can only be granted outside an interactive terminal when the command declares a consent token.",
},
],
});
});

test("--confirm shows up in help as part of the shared flag family", async () => {
Expand Down
12 changes: 9 additions & 3 deletions packages/cli-engine/tests/prompts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ describe("consent", () => {
code: "CLI.CONSENT_REQUIRED",
severity: "error",
summary:
'"Delete everything?" requires explicit consent, which --yes cannot grant.',
"This command requires explicit consent, and --yes does not give it.",
why: "Delete everything?",
nextActions: [
{
kind: "user-choice",
Expand All @@ -291,8 +292,13 @@ describe("consent", () => {
expect(result.exitCode).toBe(2);
const last = result.json[result.json.length - 1];
expect(
last.kind === "result" && !last.envelope.ok && last.envelope.error.code,
).toBe("CLI.CONSENT_REQUIRED");
last.kind === "result" && !last.envelope.ok && last.envelope.error,
).toMatchObject({
code: "CLI.CONSENT_REQUIRED",
summary:
"This command requires explicit consent, but it was not provided.",
why: "Delete everything?",
});
});

test("an explicit interactive yes grants consent", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/e2e/address.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ describeCommands(["postgres show", "postgres delete"], () => {
);

expect(result.envelope.error?.code).toBe("CLI.CONSENT_REQUIRED");
expect(result.envelope.error?.summary).toContain(
expect(result.envelope.error?.why).toContain(
`database ${previewDatabase.id} in environment ${environment} (branch ${environment})`,
);
const after = await run([
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/e2e/scratch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export async function removeScratchProject(
if (!removal.envelope.ok) {
stranded(
`${removal.envelope.error?.code ?? "(no code)"} — ` +
`${removal.envelope.error?.summary ?? "(no summary)"}`,
`${removal.envelope.error?.summary ?? "(no summary)"}` +
(removal.envelope.error?.why === undefined
? ""
: ` (${removal.envelope.error.why})`),
);
}
} catch (failure) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"dependencies": {
"@manypkg/tools": "^2.1.2",
"@prisma/cli-engine": "workspace:0.10.2",
"@prisma/cli-engine": "workspace:0.10.3",
"@prisma/composer-cli": "0.39.0",
"@prisma/compute-sdk": "0.43.0",
"@prisma/management-api-sdk": "1.80.0",
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/scripts/conformance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,22 @@ async function tarball(): Promise<readonly Finding[]> {
{
familyPackage: "@prisma/composer-cli",
familyPin: "0.10.0",
shellPin: "0.10.2",
shellPin: "0.10.3",
channel: "dev",
reason:
"engine 0.10.2 changes the first line of the statement refusal; composer-cli still peers 0.10.0",
"engines 0.10.2 and 0.10.3 change the first line of the two consent refusals; composer-cli still peers 0.10.0",
removeWhen:
"composer-cli releases peering 0.10.2 and the follow-up bump PR pins that release",
"composer-cli releases peering 0.10.3 and the follow-up bump PR pins that release",
},
{
familyPackage: "@prisma/orm-toolchain",
familyPin: "0.10.0",
shellPin: "0.10.2",
shellPin: "0.10.3",
channel: "dev",
reason:
"engine 0.10.2 changes the first line of the statement refusal; orm-toolchain still peers 0.10.0",
"engines 0.10.2 and 0.10.3 change the first line of the two consent refusals; orm-toolchain still peers 0.10.0",
removeWhen:
"orm-toolchain releases peering 0.10.2 and the follow-up bump PR pins that release",
"orm-toolchain releases peering 0.10.3 and the follow-up bump PR pins that release",
},
],
channel: CHANNEL,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/tests/bucket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ describe("bucket commands given an address", () => {
ok: false,
error: {
code: "CLI.CONSENT_REQUIRED",
summary: expect.stringContaining(
why: expect.stringContaining(
"bucket bkt_files_main in production (branch main)",
),
meta: { consentToken: "@billing.files" },
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/tests/postgres.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2776,7 +2776,7 @@ describe("postgres commands given an address", () => {
ok: false,
error: {
code: "CLI.CONSENT_REQUIRED",
summary: expect.stringContaining(
why: expect.stringContaining(
"database db_catalog_pr42 in environment pr-42 (branch pr-42)",
),
meta: { consentToken: "@pr-42:shop.catalog" },
Expand All @@ -2796,7 +2796,7 @@ describe("postgres commands given an address", () => {
ok: false,
error: {
code: "CLI.CONSENT_REQUIRED",
summary: expect.stringContaining(
why: expect.stringContaining(
"database db_catalog_main in production (branch main)",
),
meta: { consentToken: "@shop.catalog" },
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/tests/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3128,7 +3128,7 @@ describe("project commands given an address", () => {
ok: false,
error: {
code: "CLI.CONSENT_REQUIRED",
summary: expect.stringContaining('Project "Billing" (proj_1)'),
why: expect.stringContaining('Project "Billing" (proj_1)'),
meta: { consentToken: "@billing" },
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/tests/service-address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe("service commands given an address", () => {
if (frame?.kind !== "result" || frame.envelope.ok) {
throw new Error("expected an errored envelope");
}
expect(frame.envelope.error.summary).toContain(
expect(frame.envelope.error.why).toContain(
'"hello-world" (svc_1) in production (branch main)',
);
});
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/tests/service-domain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,9 @@ describe("prisma service domain delete", () => {
throw new Error("expected an errored envelope");
}
expect(frame.envelope.error.code).toBe("CLI.CONSENT_REQUIRED");
expect(frame.envelope.error.summary).toContain("--confirm shop.acme.com");
expect(frame.envelope.error.nextActions?.[0]?.label).toContain(
"--confirm shop.acme.com",
);
expect(frame.envelope.error.meta).toMatchObject({
consentToken: "shop.acme.com",
});
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/tests/service-version-rollback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,12 @@ describe("prisma service version rollback", () => {
throw new Error("expected an errored envelope");
}
expect(frame.envelope.error.code).toBe("CLI.CONSENT_REQUIRED");
expect(frame.envelope.error.summary).toContain(
expect(frame.envelope.error.why).toBe(
'Roll back Service "hello-world" to version dep_1 and make it live?',
);
expect(frame.envelope.error.summary).toContain("--confirm dep_1");
expect(frame.envelope.error.nextActions?.[0]?.label).toContain(
"--confirm dep_1",
);
expect(frame.envelope.error.meta).toMatchObject({
consentToken: "dep_1",
});
Expand Down
2 changes: 1 addition & 1 deletion packages/prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
"dependencies": {
"@manypkg/tools": "^2.1.2",
"@prisma/cli-engine": "workspace:0.10.2",
"@prisma/cli-engine": "workspace:0.10.3",
"@prisma/composer-cli": "0.39.0",
"@prisma/compute-sdk": "0.43.0",
"@prisma/management-api-sdk": "1.80.0",
Expand Down
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading