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
19 changes: 11 additions & 8 deletions docs/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ or Shaun.
*Applies to: every error*

True for reading requests, for `messages create` with
`--client-message-id`, and for a title without a body that Minka holds back
while the document is written together ([C-203](#c-203)); false otherwise,
`--client-message-id`, and for a title that Minka holds back while the
document is written together, which goes through once nobody writes
together, or once the page saves or resets a step never saved
([C-203](#c-203)); false otherwise,
with the hint to read the state back.

**Why:** A repeated write would otherwise create a card or a comment twice.
Expand Down Expand Up @@ -3033,14 +3035,15 @@ and a bundle with such a series stops Minka's whole run.
**Implemented as:** `basecamp.eventRepetitionOf`, `basecamp.daysOf`, see [Importing from Basecamp](stable/import.md).

<a id="c-203"></a>
## C-203 — A title refused while written together is sent again later, never with a body
## C-203 — A title refused while written together is sent again later, never with another text

*Applies to: `docs edit`*

A 409 `documentChanged` on a request without a body, sent with `--force` or an
`--expect` the document still stands at, says the document is being written
together, is retryable and advises no body, merge or `--expect`. **Why:**
Minka answers it like a stale guard, and a body would end the co-editing and
lose what others typed. It is the third case of [C-012](#c-012).
A 409 `documentChanged` on a title, with or without a body, sent with `--force`
or an `--expect` the document still stands at, says the document is being
written together, is retryable, names the page as the way past a step never
saved, and advises no other text, merge or `--expect`. **Why:** Minka answers it
like a stale guard and never holds a different text back, and that text would
end the co-editing and lose what others typed. Third case of [C-012](#c-012).
**Implemented as:** `cli.titleRefusedWhileWrittenTogether`,
see [Docs & Files](stable/docs-and-files.md).
71 changes: 44 additions & 27 deletions docs/stable/docs-and-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,37 +311,54 @@ names the `--expect` to send next. An upload refuses the same way with
## A title while the document is written together

A document can be written together on its page in Minka. A `PATCH` with a
`body` ends that co-editing, and what the others typed and Minka has not saved
into the text yet is lost. A `PATCH` with a new title and no `body` never
writes the text, and so Minka refuses it while the document is written
together — the co-editing holds something unsaved, or took a step in the last
15 minutes: 409 `documentChanged` with the document under `"document"`,
guarded or not, and an `inNavigation` sent with it stays unwritten too. The
title that already stands is 200, as ever, and writes the navigation. The
navigation alone is never held back. The API does not say whether a document
is written together.
`body` that differs from the stored one ends that co-editing, and what the
others typed and Minka has not saved into the text yet is lost. A `body` equal,
once cleaned, to the stored one counts as not named. A `PATCH` with a new title
and no different `body` never writes the text, and so Minka refuses it while
the document is written together — the co-editing holds something unsaved, or
took a step in the last 15 minutes: 409 `documentChanged` with the document
under `"document"`, guarded or not, and an `inNavigation` sent with it stays
unwritten too. Where the last step on the page was never saved, waiting does
not end it: the title is refused until somebody opens the page and saves,
resets the co-editing there, or a different text is written. The title and the
text that already stand are 200, as ever, and write the navigation. The
navigation alone, and a text alone, are never held back. The API does not say
whether a document is written together.

Minka sends the same code and the same message as for a stale guard, and the
`updatedAt` may not have moved, so `docs edit` tells the two apart by what it
sent ([C-203](../decisions.md#c-203)):

- **No `--body`, and `--force` or an `--expect` the document still stands
at:** nothing but the co-editing can have refused it. The error says the
document is being written together on its page and that nothing was
written — the title, and the place in the navigation where it was given —,
is `retryable`, and the hint says to run the same command again later. It
advises neither a body, nor merging, nor an `--expect`: a body would end the
co-editing, and the same `--expect` meets the same refusal.
- **No `--body`, and an `--expect` the document has moved past:** either
refusal is possible. The error names both, is not retryable, and the hint
says to send the title again with the new `--expect`, without `--body`;
refused again at that `updatedAt`, the document is being written together.
- **A `--body`:** Minka does not hold it back, so a 409 is a document written
over since, with the advice to merge.
sent ([C-203](../decisions.md#c-203)). It does not compare the body: a
different one is never held back.

- **A `--title`, and `--force` or an `--expect` the document still stands
at:** nothing but the co-editing can have refused it, with or without
`--body`. The error says the document is being written together on its page
and that nothing was written — the title, the body where it was given, and
the place in the navigation where it was given —, is `retryable`, and the
hint says to run the same command again later. Refused still, the last step
on the page may never have been saved: the hint names the document's page,
where somebody saves or resets the co-editing. It advises neither another
text, nor merging, nor an `--expect`: another text would end the co-editing,
and the same `--expect` meets the same refusal.
- **A `--title` without `--body`, and an `--expect` the document has moved
past:** either refusal is possible. The error names both, is not retryable,
and the hint says to send the title again with the new `--expect`, without
`--body`; refused again at that `updatedAt`, the document is being written
together.
- **A `--title` with `--body`, and an `--expect` the document has moved
past:** either refusal is possible. The error names both and is not
retryable. The hint names the condition: if the body is the writer's own
change, merge it and send it again with the new `--expect`, which ends the
co-editing on the page and loses the others' unsaved typing. If only the
title is the writer's change, send it with the text as it stands and the new
`--expect`; refused again there, the document is being written together, and
no different text is sent to get the title through.
- **A `--body` without `--title`:** Minka does not hold it back, so a 409 is a
document written over since, with the advice to merge.

`docs edit` is the only command that sends a `PATCH` to a document. The help
of `docs edit` warns that `--body`, with `--expect` or `--force`, ends the
co-editing on the page and loses what others typed but did not save.
of `docs edit` warns that a different `--body`, with `--expect` or `--force`,
ends the co-editing on the page and loses what others typed but did not save.

## Whom a new document reaches

Expand Down Expand Up @@ -416,7 +433,7 @@ often they are named.
| — | `docs uploads create <file> --project` naming another project than the tool's, before the file travels | 2 |
| 415 `unsupportedMediaType` | unreachable: every write of this CLI sends JSON | — |
| 400 `malformedBody` | unreachable: a moment `--expect` lets through is one the server reads, and a `--blob` that is no ID exits 1 | — |
| 409 `documentChanged` | `docs edit --expect` against a document written over since; `docs edit --title` without `--body` while the document is written together on its page, guarded or not, after the text that stands already; retryable with `--force` or an `--expect` the document still stands at, not with an older `--expect` | 9 |
| 409 `documentChanged` | `docs edit --expect` against a document written over since; `docs edit --title`, without `--body` or with the text that stands, while the document is written together on its page, guarded or not; a title and a text that both equal the stored ones are 200 instead; retryable with `--force` or an `--expect` the document still stands at, not with an older `--expect` | 9 |
| 409 `uploadChanged` | `docs uploads edit --expect` against an upload written over since | 9 |
| 422 `uploadTitleMissing`, `uploadTitleTooLong`, `uploadTitleHasControlCharacters` | `docs uploads edit`; of `docs uploads create`, all but an empty title, which exits 1 before anything goes out | 9 |
| 422 `uploadDescriptionTooLong`, `uploadDescriptionNotReadable` | `docs uploads create`, `docs uploads edit` | 9 |
Expand Down
9 changes: 5 additions & 4 deletions docs/stable/output-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ not place the failure at all (C-069).

`retryable` is true only for reading requests, for `messages create` with
`--client-message-id`, because a second attempt then writes nothing new, and
for a title of `docs edit` without `--body` that Minka holds back while the
document is written together on its page, sent with `--force` or an `--expect`
the document still stands at: nothing was written, and the same command is
what goes through once nobody writes together (C-203). A
for a title of `docs edit` that Minka holds back while the document is
written together on its page, sent with `--force` or an `--expect` the
document still stands at: nothing was written, and the same command is what
goes through once nobody writes together, or, where the last step on the page
was never saved, once somebody saves or resets the co-editing there (C-203). A
failed write may have arrived; there the `hint` advises reading the state back
(C-012).

Expand Down
14 changes: 9 additions & 5 deletions docs/work-in-progress/status.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,15 @@ What the API does not offer — drafts above all — is named there and nowhere
pretended. None of it has been seen live: the whole feature is checked against
the fake, see below.

A title without a body that Minka refuses while the document is written
together on its page is told apart from a document written over, retryable and
without advice to send a body (C-203). Minka's side is on its `main` and in no
release yet; the CLI is built against Minka's code and tests and the fake, not
live-checked. A released Minka writes such a title.
A title, without a body or with the text that stands, that Minka refuses
while the document is written together on its page is told apart from a
document written over, retryable, names the page as the way past a step never
saved, and gives no advice to send a different text (C-203). Minka's side is on
its `main` and in no release yet; the CLI is built against Minka's code and
tests and the fake, not live-checked. A released Minka writes a title alone,
and with any body ends the co-editing. The fake compares a body as its own
cleaning keeps it (trimmed, plain text escaped into a div, decisions blocks
kept): it strips no attributes or elements, as Minka's sanitizer does.

A tool is kept in order with `delete`, `restore`, `archive`, `unarchive` and
`move` in `docs`, `docs uploads` and `docs folders`, beside `docs folders
Expand Down
4 changes: 2 additions & 2 deletions internal/api/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ func (c *Client) CreateDocument(ctx context.Context, toolID string, input Create
// UpdateDocument writes over a document. A document written over since the
// moment the input names is left as it stands and answered with 409
// documentChanged, whose body carries it under "document". So is a new title
// without a body while the document is written together on its page, guarded
// or not.
// without a body, or with the text that stands, while the document is written
// together on its page, guarded or not.
func (c *Client) UpdateDocument(ctx context.Context, documentID string, input UpdateDocumentInput) (Result[Document], error) {
return request[Document](ctx, c, http.MethodPatch, "/documents/"+url.PathEscape(documentID), input)
}
Expand Down
71 changes: 44 additions & 27 deletions internal/cli/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,20 @@ documentChanged). Merge your text into it and send it again with its updatedAt.
--expect none is not a value here: it belongs to the notes of a card, where it
means that nobody has written any.

Others may be writing the document together on its page in Minka. A --body,
with --expect or with --force, ends that co-editing: what they typed and Minka
has not saved into the text yet is lost. A --title without --body keeps their
Others may be writing the document together on its page in Minka. A --body
that differs from the text that stands, with --expect or with --force, ends
that co-editing: what they typed and Minka has not saved into the text yet is
lost. A --title without --body, or with the text that stands, keeps their
typing, and so Minka refuses it while somebody writes the document together or
did in the last 15 minutes: exit 9 (meta.apiCode documentChanged), the document
printed as it stands, neither the title nor the navigation written. With
--force or an --expect the document still stands at, the error says so and is
retryable: run the same command again later. With an --expect the document has
moved past, it names both causes and is not retryable: send the title again
with the new updatedAt. Never send a body to get past it.
printed as it stands, nothing written, the navigation neither. With --force or
an --expect the document still stands at, the error says so and is retryable:
run the same command again later. Where the last step on the page was never
saved, waiting does not help: somebody has to open the document's page in
Minka and save, or reset the co-editing there. With an --expect the document
has moved past, it names both causes and is not retryable: send the title
again with the new updatedAt. Never send a different text to get the title
through.

The guard reaches only as far as Minka's own clock: the moment of a document is
kept to the whole second, so a change made in the same second as your read is
Expand Down Expand Up @@ -485,10 +489,10 @@ navigation, as from a Minka that does not know books, is exit 7 (api_error).`,
}
e = entryConflict(a, e, err, apiCodeDocumentChanged, "document",
func(d api.Document) string { return d.UpdatedAt }, renderDocument)
if input.Body == nil {
return titleRefusedWhileWrittenTogether(e, guard, input.InNavigation != nil)
if input.Title == nil {
return e
}
return e
return titleRefusedWhileWrittenTogether(e, guard, input.Body != nil, input.InNavigation != nil)
}

// A Minka without books answers 200 and writes no navigation; only
Expand Down Expand Up @@ -1484,14 +1488,16 @@ func commentRefusal(s *session, err error) *Error {
return e
}

// titleRefusedWhileWrittenTogether tells a refused write without a body from
// one written over. Minka refuses a title without a body while the document is
// written together on its page, with the same code and the same message as for
// a stale expectation, and the document's moment may not have moved. Without a
// guard, or with one the document still stands at, nothing else can have
// refused it, and sending the same again later is the way out. Advice to merge
// or to send a body would end the co-editing and lose what others typed.
func titleRefusedWhileWrittenTogether(e *Error, guard *string, navigation bool) *Error {
// titleRefusedWhileWrittenTogether tells a refused title from a document
// written over. Minka refuses a new title, alone or with the text that stands,
// while the document is written together on its page, with the same code and
// the same message as for a stale expectation, and the document's moment may
// not have moved. A different text is never held back, so without a guard, or
// with one the document still stands at, nothing else can have refused it, and
// sending the same again later is the way out. Where the last step on the page
// was never saved, only the page itself or a different text ends the refusal,
// and a different text loses what others typed.
func titleRefusedWhileWrittenTogether(e *Error, guard *string, body, navigation bool) *Error {
current, ok := e.Data.(json.RawMessage)
if e.APICode != apiCodeDocumentChanged || !ok {
return e
Expand All @@ -1500,19 +1506,30 @@ func titleRefusedWhileWrittenTogether(e *Error, guard *string, navigation bool)
if json.Unmarshal(current, &document) != nil {
return e
}
stays := "the title stays as it was"
switch {
case body && navigation:
stays = "the title, the body and the place in the navigation stay as they were"
case body:
stays = "the title and the body stay as they were"
case navigation:
stays = "the title and the place in the navigation stay as they were"
}
neverADifferentText := " Never send a different text to get the title through: it ends the co-editing and loses what others typed but did not save."
if guard != nil && !sameMoment(*guard, document.UpdatedAt) {
e.Message = "the document was written over since it was read, or is being written together on its page; nothing was written, the title stays as it was"
if navigation {
e.Message = "the document was written over since it was read, or is being written together on its page; nothing was written, the title and the place in the navigation stay as they were"
}
e.Message = "the document was written over since it was read, or is being written together on its page; nothing was written, " + stays
e.Hint = "Send the title again with --expect " + document.UpdatedAt + ", without --body. Refused again at that updatedAt, the document is being written together on its page: try again later."
if body {
e.Hint = "If the body is your own change, merge it into the document as it stands and send it again with --expect " + document.UpdatedAt + ": a different text ends the co-editing on the page and loses what others typed but did not save. If only the title is your change, send it with the text as it stands and --expect " + document.UpdatedAt + "; refused again at that updatedAt, the document is being written together on its page: try again later, and never send a different text to get the title through."
}
return e
}
e.Message = "the document is being written together on its page; nothing was written, the title stays as it was"
if navigation {
e.Message = "the document is being written together on its page; nothing was written, the title and the place in the navigation stay as they were"
e.Message = "the document is being written together on its page; nothing was written, " + stays
page := "the document's page in Minka"
if document.AppURL != "" {
page += " (" + document.AppURL + ")"
}
e.Hint = "Minka takes no title without a body while somebody writes the document together on its page, or did in the last 15 minutes. Run the same command again later."
e.Hint = "Minka takes no new title, alone or with the text that stands, while somebody writes the document together on its page or did in the last 15 minutes. Run the same command again later. Refused still, the last step on the page may never have been saved: somebody has to open " + page + " and save, or reset the co-editing there." + neverADifferentText
e.Retryable = true
return e
}
Expand Down
Loading