diff --git a/docs/reference/error-reference.md b/docs/reference/error-reference.md index c197eee8..2cfdbc88 100644 --- a/docs/reference/error-reference.md +++ b/docs/reference/error-reference.md @@ -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 `, 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:'`. `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:'`. 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 diff --git a/packages/cli-engine/package.json b/packages/cli-engine/package.json index e122f034..7e1631a0 100644 --- a/packages/cli-engine/package.json +++ b/packages/cli-engine/package.json @@ -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": { diff --git a/packages/cli-engine/src/execution/prompts.ts b/packages/cli-engine/src/execution/prompts.ts index c8c2a754..6875ae3a 100644 --- a/packages/cli-engine/src/execution/prompts.ts +++ b/packages/cli-engine/src/execution/prompts.ts @@ -158,6 +158,7 @@ function answerFromFlags( function strayFlagLines( state: RunState, subjects: readonly string[], + verbs: readonly string[], ): readonly string[] { const unmatched = state.statementValues.filter( (value) => @@ -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.`, ), ]; } @@ -181,14 +182,14 @@ function statementUnavailable( 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( @@ -199,8 +200,12 @@ function statementUnavailable( .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) => ({ diff --git a/packages/cli-engine/tests/consent-leftovers.test.ts b/packages/cli-engine/tests/consent-leftovers.test.ts index 931fd90f..edfe8b43 100644 --- a/packages/cli-engine/tests/consent-leftovers.test.ts +++ b/packages/cli-engine/tests/consent-leftovers.test.ts @@ -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", @@ -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"] }, }); }); @@ -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"] }] }, }); }); diff --git a/packages/cli-engine/tests/statement-prompts.test.ts b/packages/cli-engine/tests/statement-prompts.test.ts index 185ade73..b675d0bf 100644 --- a/packages/cli-engine/tests/statement-prompts.test.ts +++ b/packages/cli-engine/tests/statement-prompts.test.ts @@ -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", @@ -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:'", ); @@ -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"], { @@ -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", @@ -330,6 +364,19 @@ 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"]); @@ -337,8 +384,7 @@ describe("prompt.statements asks several questions together", () => { 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: [ { diff --git a/packages/cli/package.json b/packages/cli/package.json index 941a580a..60ea193e 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -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", diff --git a/packages/prisma/package.json b/packages/prisma/package.json index 52a9887e..310c3f7e 100644 --- a/packages/prisma/package.json +++ b/packages/prisma/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 640f5a47..09631fdc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -27,7 +27,7 @@ importers: specifier: ^2.1.2 version: 2.1.2 '@prisma/cli-engine': - specifier: workspace:0.10.0 + specifier: workspace:0.10.1 version: link:../cli-engine '@prisma/composer-cli': specifier: 0.39.0 @@ -210,7 +210,7 @@ importers: specifier: ^2.1.2 version: 2.1.2 '@prisma/cli-engine': - specifier: workspace:0.10.0 + specifier: workspace:0.10.1 version: link:../cli-engine '@prisma/composer-cli': specifier: 0.39.0