Skip to content
Draft
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
2 changes: 1 addition & 1 deletion docs/reference/error-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ The config file's `$prismaConfig` marker declares a version other than the one t

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 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 names the subjects, `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, and the next actions give one flag to pass per verb, such as `--delete Legacy` or `--rename 'Legacy:<new name>'`. With one question unanswered, the summary is the command's question and `why` says that the user has to choose and that the run cannot ask (or, under `--yes`, that `--yes` does not choose). With several, the summary gives their number and `why` carries the questions. `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.0",
"version": "0.10.1",
"description": "The execution engine of the unified Prisma CLI.",
"type": "module",
"exports": {
Expand Down
27 changes: 16 additions & 11 deletions packages/cli-engine/src/execution/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ function answerFromFlags<V extends string>(
function strayFlagLines(
state: RunState,
subjects: readonly string[],
verbs: readonly string[],
): readonly string[] {
const unmatched = state.statementValues.filter(
(value) =>
Expand All @@ -167,11 +168,11 @@ function strayFlagLines(
return [
...unmatched.map(
(value) =>
`${flagForm(value.verb, value.values)} answers no question; the questions are about ${subjects.join(", ")}.`,
`${flagForm(value.verb, value.values)} does not name ${subjects.join(" or ")}.`,
),
...state.confirmValues.map(
(token) =>
`${flagForm("confirm", [token])} answers no consent in this run; a statement flag is what answers these questions.`,
`${flagForm("confirm", [token])} does not choose what happens; ${verbs.map((verb) => `--${verb}`).join(" or ")} does.`,
),
];
}
Expand All @@ -181,14 +182,14 @@ function statementUnavailable<V extends string>(
subjects: readonly string[],
state: RunState,
): CliStructuredError {
const quoted = unanswered.map((question) => `"${question.subject}"`);
const situation = state.yes
? "which --yes cannot give"
: "and the session is not interactive";
const summary =
unanswered.length === 1
? `${quoted[0]} needs a statement, ${situation}.`
: `${unanswered.length} subjects need a statement, ${situation}: ${quoted.join(", ")}.`;
? "--yes does not choose for you"
: "this run cannot ask you";
const [only, ...others] = unanswered;
const alone = others.length === 0;
const summary = alone
? only.question
: `${unanswered.length} choices are needed, and ${situation}.`;
const listed = unanswered.map(({ subject, verbs }) => ({ subject, verbs }));
const unmatched = state.statementValues
.filter(
Expand All @@ -199,8 +200,12 @@ function statementUnavailable<V extends string>(
.map(({ verb, values }) => ({ verb, values }));
return new CliStructuredError("CLI.CONSENT_REQUIRED", summary, {
why: [
...unanswered.map((question) => question.question),
...strayFlagLines(state, subjects),
...(alone
? [`You have to choose what happens, and ${situation}.`]
: unanswered.map((question) => question.question)),
...strayFlagLines(state, subjects, [
...new Set(unanswered.flatMap((question) => question.verbs)),
]),
].join("\n"),
nextActions: unanswered.flatMap((question) =>
question.verbs.map((verb) => ({
Expand Down
6 changes: 3 additions & 3 deletions packages/cli-engine/tests/consent-leftovers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe("an unconsumed --confirm token", () => {
});
});

test("is reported with a statement refusal, which says a statement flag answers it", async () => {
test("is reported with a statement refusal, which names the flags that choose", async () => {
const result = await cliWith(askBoth).run([
"probe",
"--confirm",
Expand All @@ -109,7 +109,7 @@ describe("an unconsumed --confirm token", () => {

expect(errorOf(result)).toMatchObject({
code: "CLI.CONSENT_REQUIRED",
why: "What happens to Legacy?\nWhat happens to User.nickname?\n--confirm mydb answers no consent in this run; a statement flag is what answers these questions.",
why: "What happens to Legacy?\nWhat happens to User.nickname?\n--confirm mydb does not choose what happens; --rename or --delete does.",
meta: { confirm: ["mydb"] },
});
});
Expand All @@ -126,7 +126,7 @@ describe("a statement value that matches no question", () => {

expect(errorOf(result)).toMatchObject({
code: "CLI.CONSENT_REQUIRED",
why: "What happens to Legacy?\nWhat happens to User.nickname?\n--delete Legcy answers no question; the questions are about Legacy, User.nickname.",
why: "What happens to Legacy?\nWhat happens to User.nickname?\n--delete Legcy does not name Legacy or User.nickname.",
meta: { unmatched: [{ verb: "delete", values: ["Legcy"] }] },
});
});
Expand Down
70 changes: 58 additions & 12 deletions packages/cli-engine/tests/statement-prompts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,15 @@ describe("a verb flag answers the statement", () => {
});

describe("without a flag, a non-interactive run refuses", () => {
test("the refusal names the subject and one flag form per verb", async () => {
test("the refusal leads with the question and gives one flag form per verb", async () => {
const result = await cliWith(askLegacy).run(["probe", "--json"]);

expect(result.exitCode).toBe(2);
expect(errorOf(result)).toEqual({
code: "CLI.CONSENT_REQUIRED",
severity: "error",
summary:
'"Legacy" needs a statement, and the session is not interactive.',
why: LEGACY_QUESTION,
summary: LEGACY_QUESTION,
why: "You have to choose what happens, and this run cannot ask you.",
nextActions: [
{
kind: "user-choice",
Expand All @@ -214,16 +213,19 @@ describe("without a flag, a non-interactive run refuses", () => {
);

expect(result.exitCode).toBe(2);
expect(errorOf(result)?.summary).toBe(
'"Legacy" needs a statement, which --yes cannot give.',
);
expect(errorOf(result)).toMatchObject({
summary: LEGACY_QUESTION,
why: "You have to choose what happens, and --yes does not choose for you.",
});
});

test("the human refusal prints each flag form as a next action", async () => {
const result = await cliWith(askLegacy).run(["probe", "--format", "human"]);

expect(result.exitCode).toBe(2);
expect(result.stderr).toContain("[CLI.CONSENT_REQUIRED]");
expect(result.stderr).toContain(
`[CLI.CONSENT_REQUIRED] ${LEGACY_QUESTION}`,
);
expect(result.stderr).toContain(
"Run the command again with --rename 'Legacy:<new name>'",
);
Expand All @@ -233,6 +235,38 @@ describe("without a flag, a non-interactive run refuses", () => {
});
});

describe("a refusal of one question with a flag that answers nothing", () => {
test("says which subject a statement flag does not name", async () => {
const result = await cliWith(askLegacy).run([
"probe",
"--delete",
"Legcy",
"--json",
]);

expect(errorOf(result)).toMatchObject({
code: "CLI.CONSENT_REQUIRED",
summary: LEGACY_QUESTION,
why: "You have to choose what happens, and this run cannot ask you.\n--delete Legcy does not name Legacy.",
});
});

test("says which flags choose when --confirm was given", async () => {
const result = await cliWith(askLegacy).run([
"probe",
"--confirm",
"mydb",
"--json",
]);

expect(errorOf(result)).toMatchObject({
code: "CLI.CONSENT_REQUIRED",
summary: LEGACY_QUESTION,
why: "You have to choose what happens, and this run cannot ask you.\n--confirm mydb does not choose what happens; --rename or --delete does.",
});
});
});

describe("an interactive run asks", () => {
test("a bare verb answers with the subject", async () => {
const result = await cliWith(askLegacy).run(["probe"], {
Expand Down Expand Up @@ -312,8 +346,8 @@ describe("prompt.statements asks several questions together", () => {
expect(result.exitCode).toBe(2);
expect(errorOf(result)).toMatchObject({
code: "CLI.CONSENT_REQUIRED",
summary:
'"User.name" needs a statement, and the session is not interactive.',
summary: USER_NAME_QUESTION,
why: "You have to choose what happens, and this run cannot ask you.",
nextActions: [
{
kind: "user-choice",
Expand All @@ -330,15 +364,27 @@ describe("prompt.statements asks several questions together", () => {
});
});

test("--yes answers none of several questions", async () => {
const result = await cliWith(askBoth).run(
["probe", "--yes", "--json"],
INTERACTIVE,
);

expect(errorOf(result)).toMatchObject({
code: "CLI.CONSENT_REQUIRED",
summary: "2 choices are needed, and --yes does not choose for you.",
why: `${LEGACY_QUESTION}\n${USER_NAME_QUESTION}`,
});
});

test("one refusal lists every unanswered question", async () => {
const result = await cliWith(askBoth).run(["probe", "--json"]);

expect(result.exitCode).toBe(2);
expect(errorOf(result)).toEqual({
code: "CLI.CONSENT_REQUIRED",
severity: "error",
summary:
'2 subjects need a statement, and the session is not interactive: "Legacy", "User.name".',
summary: "2 choices are needed, and this run cannot ask you.",
why: `${LEGACY_QUESTION}\n${USER_NAME_QUESTION}`,
nextActions: [
{
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.0",
"@prisma/cli-engine": "workspace:0.10.1",
"@prisma/composer-cli": "0.39.0",
"@prisma/compute-sdk": "0.43.0",
"@prisma/management-api-sdk": "1.80.0",
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.0",
"@prisma/cli-engine": "workspace:0.10.1",
"@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