Skip to content

fix(golang): say what a "not an object" error found, and that guest answers are internal - #2006

Merged
coderdan merged 17 commits into
nextfrom
fix/go-not-an-object-errors
Nov 28, 2026
Merged

coderdan merged 17 commits into
nextfrom
fix/go-not-an-object-errors

Conversation

@coderdan

@coderdan coderdan commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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 found detail that it adds.

Closes #1987. Closes #2007.

Changes

  1. O2, decrypting a map field.
  2. N1, the vars of a JSON match query.
    • Before: json_input, "the input is not the object the JSON operator takes".
    • Now: a new reason, json_vars_not_object, with found: "match takes its vars as a JSON object, found null (field "…")". The dynamic and typed paths share one check.
    • The Rust tests cover array, null, string, the three number kinds and bool. The Go test checks that Reason, Found and Field reach Go.
  3. O3, O4 and O5, guest answers. These stay ErrInternal, built by a new guest.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".
    • This applies to se_query_term, se_targets, se_operators and se_contexts, and to the auth exports sa_token, sa_secret_key and sa_device_identity.
    • Tests cover KindOf, BadAnswer, each message, and O5, which had none.
  4. Docs and changelogs. The stashgen README, the gensupport docs, and both CHANGELOGs.

Verification

  • Mutation testing (--in-diff): 11 mutants, 8 caught, 3 that did not compile.
  • Go guest: fmt, clippy and tests under all four feature sets.
  • Go: with all five guests rebuilt at this branch's head, gofmt, go vet and go test ./... pass in all three modules, with STACK_CONFORMANCE_REQUIRED=1.
  • recipher-js: clippy and tests.

Review notes

  • Breaking for json_input. N1 replaces the json_input reason with json_vars_not_object for this case. A Go program that switched on json_input for vars needs the new name. Both CHANGELOGs say so. Keeping json_input and adding only found is the alternative, but then the message cannot say "vars" or "match".
  • Version skew is named in the message. These errors have no help field, so the note about a guest that does not match the module's version goes in the message itself.

…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
@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 100df4e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI; Enforced overrides: Organization
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 156d537e-9b5a-4f00-a845-7f81e8524c0d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

@coderdan coderdan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Mutation testing (cargo-mutants, --in-diff, stack-auth, stack-encrypt, stack-encrypt-jsonpath, vitaminc-aead, recipher-frame, vitaminc-aead-derive)

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.
@coderdan

Copy link
Copy Markdown
Contributor Author

The review's findings outside the diff are fixed in 4398299:

  • Decode failures now go through BadAnswer for every export: se_query_term, se_targets, se_operators, se_contexts, se_verify and se_target_limit, through a new decodeAnswer. In auth, so do object(), the workspace list and sa_auth_runnable. BadAnswer wraps the problem with %w. A decode failure is tested for each export.
  • Inner checks: every remaining %T in checker.go and query.go now uses KindOf.
  • json.go: GetDocument's errors start gensupport: decrypt: field %q.
  • Vars first: read_match again refuses vars that are not an object before it reads the predicate, through a shared vars_object. A non-UTF-8 predicate with vars [] gets json_vars_not_object.
  • CHANGELOG: it now says only the dynamic path can receive vars that are not an object.

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 gensupport: decrypt: field "x": cipherstash: malformed input: does not open as an object, and map[string]any needs one. The tests check that it names no kind. The older mismatch() helper does the same on next, and is tracked in #2007.

The engine branch's review fixes (#2005) are merged in. gofmt, vet and the Go tests pass with STACK_CONFORMANCE_REQUIRED=1.

@coderdan
coderdan marked this pull request as ready for review November 27, 2026 16:09
@coderdan
coderdan requested a review from a team as a code owner November 27, 2026 16:09

@cipherstash-agent cipherstash-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 on mismatch() / #2007. These sites do not go through mismatch, so the #2007 fix will not reach them, yet each still names what the decrypted value opened as, under the new gensupport: decrypt: field %q: prefix:

    • convert.go:48 says the row holds a null (opened as nothing).
    • :186 is the slice path.
    • :199 is the array path, and also prints the element count (opened as []interface {} with 7 elements, not [4]string).
    • :228 is the fallback.
    • gensupport/codec.go:415 is Opaque.

    Have each name only the target type, and extend assertNamesNoKind to 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 helpers text, bytes, optionalText and uint64Field (:571–:615), and auth/token.go:62, still return plain ErrInternal, with no export name and no version hint. An sa_token answer that has no access_token reads internal guest failure: the guest's result has no access_token, which contradicts the CHANGELOG's claim for sa_token, sa_secret_key and sa_device_identity. Carry the export on fields and return guest.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 bare fmt.Errorf("%w: %v", ErrInternal, err) or %T and do not go through BadAnswer, although commit 4398299 says every encrypt export does:

    • se_json_open: json.go:129–135, :74, :80, :410, :634 and :637.
    • se_decrypt_record: records.go:508–547.
    • se_encrypt_record: records.go:92–98.
    • The step decoders: encrypt/step.go:88 and auth/step.go:77. Source: mattpocock-skills:code-review agent
  • packages/stack-encrypt/src/refusal.rs:176 (outside diff) minor The new vars refusal renders as record 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 to Error::Source and was already there, but every Reason::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 found should name numbers by engine width (uint64/int64/float64, which shows the sign of caller-sent vars) or as one kind, "number". The other is whether KindOf should name the decoder's time.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

Comment thread languages/golang/CHANGELOG.md Resolved
Comment thread languages/golang/CHANGELOG.md Resolved
Comment thread languages/golang/encrypt/query.go Resolved
Comment thread languages/golang/encrypt/checker.go Resolved
…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.
@coderdan

Copy link
Copy Markdown
Contributor Author

The review's findings outside the diff are fixed in 94e0961:

  • Decrypt paths that named a kind. They now say only "does not open as ", with no kind, no Go type of the value and no element count. This covers convert.go's nil case ("opened as nothing"), the slice, array and fallback paths, and Opaque. mismatch() itself is fixed too, so this pull request now also closes Go SDK: a decrypt error names the Go type of the decrypted value ("opened as string, not int64") #2007. assertNamesNoKind covers each site.
  • auth answer fields. fields now carries the export. text, bytes, optionalText, uint64Field and the token's expiry refuse through BadAnswer.
  • Remaining decode paths. se_json_open, se_encrypt_record and se_decrypt_record decode through DecodeAnswer, and their shape checks go through BadAnswer. se_json_open and se_decrypt_record return plaintext, so their refusals name a position or a key, never a kind. Malformed steps are BadAnswer errors naming se_io and sa_auth_io.
  • The "record source" prefix on query refusals. Fixed on the engine branch (fix(stack-encrypt): say what a record found where it takes an object, and where #2005). A refusal only a query's input can meet now starts "query input does not fit the field".

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.
Base automatically changed from fix/engine-not-an-object-errors to next November 28, 2026 12:52
@coderdan
coderdan merged commit 8f0e258 into next Nov 28, 2026
120 of 152 checks passed
@coderdan
coderdan deleted the fix/go-not-an-object-errors branch November 28, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants