Repository navigation
fix(golang): say what a "not an object" error found, and that guest answers are internal - #2006
Conversation
…nswers are internal
A Go user could see "not an object" in four places, and none said what was
there in words, or which operation it was: a map field that opened as
another kind printed a Go type (`[]interface {}`) and never said decrypt;
a Match whose vars were not an object said "the input is not the object the
JSON operator takes"; and a guest answer this module could not read said
"came back as T, not an object", which reads like bad input when it is an
internal failure.
- O2: a map field (`map[string]V`, `Values`, `map[string]any`) that opens
as something else is `decrypt: field "x": ... opened as a list, and
map[string]any needs an object`. The kind is in words, never the value.
- N1: the engine gives vars that are not a JSON object their own reason,
`json_vars_not_object`, with `found` (`array`, `uint64`, `null`, ...),
and says `match takes its vars as a JSON object, found null`. The typed
and the dynamic paths share the check; the field reaches Go's
`Diagnostic.Field`.
- O3, O4, O5: answers from se_query_term, se_targets, se_operators,
se_contexts, sa_token, sa_secret_key and sa_device_identity that this
module cannot read stay ErrInternal. They now name the export, say what
the answer is by its kind, and say this is a bug or a guest that does
not match this module's version, through one helper,
`guest.BadAnswer`, with `guest.KindOf` for the words.
Tests cover each message, including O2's and O5's, which had none.
Stacked on the engine branch for the row and found fields it adds.
Closes #1987
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
coderdan
left a comment
There was a problem hiding this comment.
Code review (/code-review medium) of de8f63f. Six nits, no bugs. I checked the KindOf and decode-path findings against the code.
Note for whoever merges second: KindOf names vcvalue types, which #2003 (stage 3) removes. Whichever of #2003 and this pull request merges second needs a small update.
Findings on lines outside the diff:
languages/golang/encrypt/query.go:168 (outside the diff) An answer that does not decode at all still neither names the export nor says it is a bug, as the CHANGELOG says it now does. query.go:168 (se_query_term), checker.go:82, :109 and :148 (se_targets, se_operators, se_contexts), and query.go:323 and :366 still return fmt.Errorf("%w: %v", ErrInternal, err). The auth decode path names the export, but leaves out the version hint.
Failure scenario: se_query_term returns bytes the codec cannot decode: cipherstash: internal guest failure: <codec error>, with no export named and no hint.
languages/golang/encrypt/checker.go:218 (outside the diff) Messages under one BadAnswer mix two styles. The outer layers use KindOf, but parseTarget's inner checks still use %T: indexes is %T, not a list (218), an index is %T (223), producible is %T (241), %s is %T, not a string (367). So do parseQueryTerm's a term part is %T (query.go:243) and term is %T (:254).
Failure scenario: "target 0: indexes is string, not a list" sits beside "target 0 is a string, not an object".
languages/golang/encrypt/gensupport/json.go:121 (outside the diff) The decrypt errors in json.go (121, 125) still start gensupport: field %q, and line 121 still says opened as %T, while Get's errors now start gensupport: decrypt: field %q and use words.
Failure scenario: A JSON field that opens as a list: "…the document opened as []interface {}, not its JSON text"; a map field in the same row: "gensupport: decrypt: field "tags": … opened as a list, …".
packages/stack-encrypt/src/dynamic/json_query.rs:685 (outside the diff) Moving the vars check into Input::predicate changes which refusal wins. The predicate's UTF-8 check now runs first, so a non-UTF-8 predicate with vars [] reports json_input for the text, and json_vars_not_object never appears. Before, the vars were refused first.
Failure scenario: A dynamic match with a non-UTF-8 predicate and vars [] gets a different refusal than before.
packages/stack-encrypt/CHANGELOG.md:659 (outside the diff) "The dynamic and the typed paths refuse them alike" is not reachable on the typed path. field_reference/json.rs variables() always builds a Value::Object, so the typed path never sees vars that are not an object, and no typed-path test was added.
Failure scenario: A reader expects a typed FieldReference match to be able to return json_vars_not_object; nothing produces it.
All six are nits. I will reply on the thread and here with what I changed.
Mutation testing (cargo-mutants,
|
| caught | missed | unviable | timeout |
|---|---|---|---|
| 10 | 0 | 3 | 0 |
Every mutant in the changed lines was caught by a test.
…kinds in words Review of the Go errors change found the new wording only half applied: - `KindOf` missed the vcvalue types that are not plain Go values (a sealed value, the sealed empty list and map markers, a passthrough, a value of an unknown logical type), and named any other Go value, such as an `int` or a map of a concrete type, "a single value". It now names the vcvalue types first, so a sealed value is not taken for bytes, and any other Go value by its reflect.Kind. - An answer that did not decode still bypassed `BadAnswer`, so it named neither the export nor a version mismatch. Every encrypt export's answer is now decoded by `decodeAnswer`, and se_verify's and se_target_limit's shape checks, auth's object, workspace list and runnable operations go through `BadAnswer` too. `BadAnswer` wraps the problem with %w, so the decoder's error stays matchable. - Checks inside one answer (an index, `producible`, a target's name, a term part, the term) still printed a Go type with %T. They use `KindOf`. - `GetDocument` still said `gensupport: field` and printed a Go type. It says `gensupport: decrypt: field` and the kind, as `Get` does. - In the engine, moving the vars check into `Input::predicate` let a predicate that is not UTF-8 be refused before vars that are not an object. `read_match` checks the vars first again, through the shared `vars_object`. - The CHANGELOG no longer says the typed path refuses vars that are not an object: a field reference always builds an object.
A map field, or a document field, whose stored value opened as something
else was refused saying what it opened as ("opened as a list"). The kind
of a decrypted value is known only once it is opened, so it is the
plaintext's own metadata, such as which rows hold a null or a list. The
refusals now name the field and the Go type needed and nothing about the
value: `gensupport: decrypt: field "x": ... does not open as an object,
and map[string]any needs one`, and for a document `does not open as its
JSON text`. Guest answers and input-side messages keep naming kinds: they
are not decrypted plaintext. Tests assert each message names no kind.
|
The review's findings outside the diff are fixed in 4398299:
One change beyond the review, following #2005's privacy rule: a decrypt error for a map field or a document no longer names what the value opened as (c214720). It now reads The engine branch's review fixes (#2005) are merged in. gofmt, vet and the Go tests pass with |
cipherstash-agent
left a comment
There was a problem hiding this comment.
Review attestation
Reviewed c2147202 · posted from Claude Code (scheduled routine) · claude-opus-5-5 · effort medium
Sources: code-review (medium) · claude-opus-5-5; rust-security agent · model not reported; mattpocock-skills:code-review agent · model not reported
Skills: code-review, company-skills:rust-security, mattpocock-skills:code-review, company-skills:review-cross-check
Every finding was checked against c2147202 and compared with the feedback already on this PR.
Findings (8): 2 major, 6 minor. 4 inline, 4 below.
-
languages/golang/encrypt/gensupport/convert.go:48(outside diff) major Adds to the comment onmismatch()/ #2007. These sites do not go throughmismatch, so the #2007 fix will not reach them, yet each still names what the decrypted value opened as, under the newgensupport: decrypt: field %q:prefix:convert.go:48says the row holds a null (opened as nothing).:186is the slice path.:199is the array path, and also prints the element count (opened as []interface {} with 7 elements, not [4]string).:228is the fallback.gensupport/codec.go:415isOpaque.
Have each name only the target type, and extend
assertNamesNoKindto cover them. Source: code-review (medium) · claude-opus-5-5; rust-security agent; mattpocock-skills:code-review agent -
languages/golang/auth/store.go:571(outside diff) minor The field helperstext,bytes,optionalTextanduint64Field(:571–:615), andauth/token.go:62, still return plainErrInternal, with no export name and no version hint. Ansa_tokenanswer that has noaccess_tokenreadsinternal guest failure: the guest's result has no access_token, which contradicts the CHANGELOG's claim forsa_token,sa_secret_keyandsa_device_identity. Carry the export onfieldsand returnguest.BadAnswer. Source: mattpocock-skills:code-review agent -
languages/golang/encrypt/json.go:129(outside diff) minor Adds to the decode-failure finding in this review. These still decode with a barefmt.Errorf("%w: %v", ErrInternal, err)or%Tand do not go throughBadAnswer, although commit 4398299 says every encrypt export does:se_json_open:json.go:129–135,:74,:80,:410,:634and:637.se_decrypt_record:records.go:508–547.se_encrypt_record:records.go:92–98.- The step decoders:
encrypt/step.go:88andauth/step.go:77. Source: mattpocock-skills:code-review agent
-
packages/stack-encrypt/src/refusal.rs:176(outside diff) minor The new vars refusal renders asrecord source does not fit the plan: match takes its vars as a JSON object, found a uint64. Match vars are not a record source, and no plan is involved. The prefix belongs toError::Sourceand was already there, but everyReason::Json*query refusal inherits it. Give query inputs their own subject, or choose the prefix from the reason. Source: mattpocock-skills:code-review agent
Not posted:
- Two findings are open design questions. One is whether
foundshould name numbers by engine width (uint64/int64/float64, which shows the sign of caller-sent vars) or as one kind, "number". The other is whetherKindOfshould name the decoder'stime.Time, which it currently calls "a struct". - One finding was refuted:
KindOf's default case cannot be reached from decoder output.
Generated by Claude Code
…s through one path
Review of the Go errors change found decrypt refusals that still named
what a value opened as, guest answers that still bypassed the shared
refusal, and a CHANGELOG that filed a break under Changed.
- Privacy. Every refusal of an opened value now names the Go type the
field needs and nothing about the value: a null for a type that holds
one ("opened as nothing"), a list or an array of another kind or length
(which printed the element count), the fallback for a type convert does
not name, an opaque value that is not bytes, and `mismatch()` itself
("opened as %T, not %T"). Each says `does not open as <type>`. The tests
assert the message names no kind and no length. The kind of a decrypted
value is the plaintext's own metadata.
- `guest.DecodeAnswer(export, out)` decodes an answer and refuses bytes
that do not decode through `BadAnswer`. `encrypt` and `auth` both use
it, and so do se_json_open, se_encrypt_record and se_decrypt_record,
whose shape checks also go through `BadAnswer`. What se_json_open and
se_decrypt_record return is plaintext, so their refusals name a
position and never a kind. A step that does not read is `BadAnswer`
naming se_io or sa_auth_io; the encrypt guest's was not ErrInternal at
all.
- auth's answer fields (`text`, `bytes`, `optionalText`, `uint64Field`)
and the token's expiry carry the export and refuse through `BadAnswer`.
- se_verify's count says "it answers 1 of 2 values".
- The vars refusal is a query refusal: the engine's `json_vars_not_object`
now says "query input does not fit the field", as the other query
refusals do since the engine branch's change.
- CHANGELOG: the `json_input` to `json_vars_not_object` rename moves to a
new Breaking section, and the guest-answer change is its own bullet,
listing every export.
|
The review's findings outside the diff are fixed in 94e0961:
Two smaller decrypt-side details are left for #2008: the opaque value's storage error text, and the out-of-range integer refusal. |
…ect-errors The engine branch rewrote its comments and Markdown in plain language. Two doc comments in refusal.rs conflicted, on `Error::Source`'s `found` field and on `Error::found`. Both keep the rewritten wording, and still say that `found` is also set for `Reason::JsonVarsNotObject`.
…n language The Go comments about guest answers and decrypt errors were hard to follow. They joined several rules with colons, and used "refusal", "does not read" and "the version hint" with no explanation. The comments now say what each function returns and what its error names. They explain an answer (the value a guest export returns) where the word first appears. They state the rule for decrypted values in the same words each time: an error never names the kind that a value decrypted to, because that kind was inside the ciphertext. Only comments and Markdown change. No message text changes.
The comments and the CHANGELOG entry for `json_vars_not_object` now use short sentences, and the entry says what a caller must change to upgrade. The comment on `misfit_text` also covers the message for a reason other than `not_an_object` that names a kind of value, such as `match takes its vars as a JSON object, found null`. Only comments and Markdown change.
…est answers Each entry now starts with what changed for a program that uses the module, then lists the details in short sentences. The entry about guest answers explains "guest", "answer" and "step" where they first appear. Only Markdown changes.
The stashgen README sentence about `vars` that write the JSON `null` had three ideas. It is now three sentences. The CHANGELOG sentence about a map field names its subject. Only Markdown changes.
…ect-errors The engine branch rewords the messages of the dynamic input errors. Both branches changed `misfit_text` in `refusal.rs`, and both added a reason at the end of the reasons table. The message for `match` vars that are not an object now starts with "the query input does not match the field", as the other query messages do. The test in `json_operators.rs` that pins that message has the new start.
The message for `match` vars that are not an object was "match takes its vars as a JSON object, found null". "Takes its vars as" is the wording of the code. "Found null" is not a sentence. The message is now one sentence: "the vars of the match are null, not a JSON object". The field follows. The other errors about a value that is not an object have the same form. The phrase of the reason is "the vars of a match must be a JSON object". Only the text changes. The reason `json_vars_not_object`, the code, and the payload fields `field` and `found` stay the same. The message names the kind of the vars and never a value. The caller sent the vars, so the engine reads that kind without decrypting anything. The Rust test and the Go test that pin the message have the new text. Both CHANGELOG entries quote the new text too.
Several messages that this branch added used the wording of the code. Examples are "does not read", "does not open as", "it answers 1 of 2 rows", and "a sealed value". A developer who gets one of these errors has to guess what they mean. The messages now say what was wrong in plain words. Only the text changes. Every error is still `ErrInternal` or `ErrEncoding`, and `errors.Is` gives the same results. - An answer that this module cannot read: "cannot read the guest's answer from se_query_term: it is a list, not an object. The cause is a bug, or a guest that does not match the version of this module". - A decrypted value of the wrong type: "the decrypted value is not of type int32". For a map field: "the decrypted value is not an object, and map[string]any needs an object". Both messages name the type that the field needs, and never the kind that the value decrypted to. - An answer with the wrong number of items says both numbers: "the number of rows is 1, not the 2 that were sent". - `KindOf` says "an encrypted value" for a sealed value, and "a value of another kind" for a Go value that it has no name for. - `expires_at` that is past the range of `time.Unix` is "too large for a time". The tests and the CHANGELOG entry that quote these messages have the new text.
…ect-errors The engine branch moves the placeholder for a source error's text into the Debug of SourceError, and `dynamic::Error` derives Debug again. The merge had no conflicts. The Go guest formats no error with Debug, so its output does not change.
Summary
The Go SDK's own "not an object" messages now say what was found, and in which operation. An internal failure, a guest answer the module cannot read, now says so, instead of reading like bad input. This PR is stacked on #2005, because N1 uses the
founddetail that it adds.Closes #1987. Closes #2007.
Changes
gensupport: field "x": …: opened as []interface {}, not an object.gensupport: decrypt: field "x": cipherstash: malformed input: does not open as an object, and map[string]any needs one. It names the operation, the field and the Go type the field needs. It does not name what the decrypted value opened as: that kind sits inside the encrypted envelope, the rule fix(stack-encrypt): say what a record found where it takes an object, and where #2005 sets. A document field reads…: does not open as its JSON text. The same rule now coversmismatch()and every other decrypt path ingensupport(Go SDK: a decrypt error names the Go type of the decrypted value ("opened as string, not int64") #2007).matchquery.json_input, "the input is not the object the JSON operator takes".json_vars_not_object, withfound: "match takes its vars as a JSON object, found null (field "…")". The dynamic and typed paths share one check.Reason,FoundandFieldreach Go.ErrInternal, built by a newguest.BadAnswer(export, problem)helper. For example: "cipherstash: internal guest failure: the guest's answer to se_query_term does not read: it is a list, not an object; this is a bug, or a guest that does not match this module's version".se_query_term,se_targets,se_operatorsandse_contexts, and to the auth exportssa_token,sa_secret_keyandsa_device_identity.KindOf,BadAnswer, each message, and O5, which had none.stashgenREADME, thegensupportdocs, and both CHANGELOGs.Verification
--in-diff): 11 mutants, 8 caught, 3 that did not compile.gofmt,go vetandgo test ./...pass in all three modules, withSTACK_CONFORMANCE_REQUIRED=1.Review notes
json_input. N1 replaces thejson_inputreason withjson_vars_not_objectfor this case. A Go program that switched onjson_inputfor vars needs the new name. Both CHANGELOGs say so. Keepingjson_inputand adding onlyfoundis the alternative, but then the message cannot say "vars" or "match".