wavetermdev/waveterm · error

json encoding: %w

Error message

json encoding: %w

What it means

When the --json flag (webGetJson) is set, webGetRun marshals the selector output with json.MarshalIndent. If marshaling fails — which is unexpected for plain string/slice output but possible for non-serializable values — the error is wrapped with "json encoding:".

Source

Thrown at cmd/wsh/cmd/wshcmd-web.go:87

		BlockId:     fullORef.OID,
		TabId:       blockInfo.TabId,
		Selector:    args[0],
		Opts: &wshrpc.WebSelectorOpts{
			Inner: webGetInner,
			All:   webGetAll,
		},
	}
	output, err := wshclient.WebSelectorCommand(RpcClient, data, &wshrpc.RpcOpts{
		Route:   wshutil.ElectronRoute,
		Timeout: 5000,
	})
	if err != nil {
		return err
	}
	if webGetJson {
		barr, err := json.MarshalIndent(output, "", "  ")
		if err != nil {
			return fmt.Errorf("json encoding: %w", err)
		}
		WriteStdout("%s\n", string(barr))
	} else {
		for _, item := range output {
			WriteStdout("%s\n", item)
		}
	}
	return nil
}

func webOpenRun(cmd *cobra.Command, args []string) (rtnErr error) {
	defer func() {
		sendActivity("web", rtnErr == nil)
	}()

	var replaceBlockORef *waveobj.ORef
	if webOpenReplaceBlock != "" {
		var err error

View on GitHub (pinned to a4447c1563)

Solutions

  1. Retry without --json; the plain-text path prints each item directly
  2. Update wsh to a version where the web get output is a JSON-serializable type
  3. If developing, ensure the output type contains only JSON-supported fields
Defensive patterns

Strategy: try-catch

Try / catch

barr, err := json.MarshalIndent(output, "", "  ")
if err != nil {
    return fmt.Errorf("json encoding: %w", err)
}

Prevention

When it happens

Trigger: `wsh web get --json` where json.MarshalIndent cannot serialize the output value (e.g. unsupported types, channels, funcs, or cyclic data introduced by upstream changes).

Common situations: Custom or corrupted builds where the output struct contains non-JSON-safe fields; very rare in practice since output is []string.

Understand the failure class

Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/a9d50bde7de3a8f3. Report an issue: GitHub.