kubernetes/kops · error
unknown delim: %v
Error message
unknown delim: %v
What it means
JSONStreamWriter.WriteToken received a json.Delim token that is not one of { [ ] }. The writer maintains pretty-printing state per delimiter, so any other delim byte cannot be serialized. This normally indicates corrupted or manually fabricated tokens being fed to the writer rather than tokens from a real json.Decoder.
Source
Thrown at pkg/jsonutils/streamwriter.go:89
j.indent += " "
j.state += "{"
case json.Delim('['):
j.indent += " "
j.state += "["
case json.Delim(']'), json.Delim('}'):
j.indent = j.indent[:len(j.indent)-2]
indent = j.indent
j.state = j.state[:len(j.state)-1]
if j.state != "" && j.state[len(j.state)-1] == 'F' {
j.state = j.state[:len(j.state)-1]
j.path = j.path[:len(j.path)-1]
}
// Don't put a comma on the last field in a block
if j.deferred == ",\n" {
j.deferred = "\n"
}
default:
return fmt.Errorf("unknown delim: %v", tt)
}
switch state {
case 0:
if err := j.writeRaw(indent + v); err != nil {
return err
}
case '{':
if err := j.writeRaw(indent + v); err != nil {
return err
}
case '[':
if err := j.writeRaw(indent + v); err != nil {
return err
}
case 'F':
if err := j.writeRaw(v); err != nil {
return errView on GitHub (pinned to 4c8573c808)
Solutions
- Only pass tokens obtained from a json.Decoder iterating valid JSON text into WriteToken.
- Check that the delimiter is one of { [ ] } before calling WriteToken, or skip punctuation tokens.
- If you need to write raw syntax characters, use writeRaw-style output or a plain writer, not WriteToken.
Example fix
// before
w.WriteToken(json.Delim(':'))
// after
if d, ok := tok.(json.Delim); ok && (d == '{' || d == '[' || d == ']' || d == '}') {
w.WriteToken(tok)
} else {
// skip non-structural delimiter tokens
} Defensive patterns
Strategy: validation
Validate before calling
func isStructuralDelim(t json.Token) bool {
d, ok := t.(json.Delim)
return ok && (d == '{' || d == '[' || d == ']' || d == '}')
}
// call: if isStructuralDelim(tok) { w.WriteToken(tok) } Type guard
func isStructuralDelim(t json.Token) bool {
d, ok := t.(json.Delim)
return ok && (d == '{' || d == '[' || d == ']' || d == '}')
} Prevention
- Feed only tokens from json.Decoder.Token() into WriteToken.
- Never construct json.Delim values by hand.
- Unit-test streaming helpers against full valid JSON documents.
When it happens
Trigger: Calling WriteToken with a json.Delim value constructed manually (e.g. json.Delim(':') or json.Delim(',')), or re-tokenizing text that was not valid JSON so the decoder yields unexpected delim bytes.
Common situations: Custom JSON rewriting tools that synthesize tokens instead of iterating a json.Decoder over valid JSON; feeding fragments of JSON (e.g. a key/value pair including its colon) through the stream writer.
Related errors
- unhandled state for json delim serialization: %v %q
- unhandled token type %T
- unhandled state for json value (%T %q) serialization: %v %q
- error parsing version spec %q
- error encoding version spec: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/b1473ec8eb16e85b.
Report an issue: GitHub.