QEMU/KVM virtual machine management via QMP
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

json: drop [encode] result form; rename [encode_exn] to [encode]

Per the ocaml-encodings convention, encoding never has a meaningful
runtime failure mode: the encoder walks the GADT and invokes
user-supplied [enc] callbacks. The only failure cases are (a) a codec
built around [Codec.ignore] (programmer error), or (b) a user-
supplied [enc] that raises (user's own bug). Neither is something a
caller should recover from, so the [result] variant was dead API
surface and every caller I've seen either [get_ok]-ed it or fell
back to [Json.Null] on error.

Drop [Codec.encode] / [Json.encode] result-returning, rename the
exception-raising [encode_exn] to just [encode]. [decode] keeps both
forms since malformed JSON is a legitimate runtime condition.

Downstream sweep: 28 files across claude / oci / atp / qemu / scitt /
yaml. Most were pattern A ([Error _ -> Json.Null ((), Meta.none)]) or
pattern B (print the error); both collapse to a direct call. Tests
using pattern F ([match Json.encode ... with Ok j -> ... | Error e
-> Alcotest.fail]) collapse to [let j = Json.encode ... in]. A few
helpers in claude/client.ml and the atp shims kept their names as
thin aliases to preserve grep targets.

+9 -15
+1 -5
lib/qmp_protocol.ml
··· 127 127 |> Object.opt_member "id" string ~enc:id 128 128 |> Object.skip_unknown |> Object.seal 129 129 130 - let to_json t = 131 - match Json.encode jsont t with 132 - | Ok json -> json 133 - | Error e -> 134 - Fmt.failwith "Failed to encode command: %s" (Json.Error.to_string e) 130 + let to_json t = Json.encode jsont t 135 131 136 132 (* Common commands *) 137 133 let qmp_capabilities = make "qmp_capabilities"
+8 -10
test/test_qmp_protocol.ml
··· 29 29 let test_version_make_roundtrip () = 30 30 (* make -> json encode -> json decode -> check fields *) 31 31 let v = Qmp.Version.make 9 0 0 "v9.0.0" in 32 - match Json.encode Qmp.Version.jsont v with 33 - | Error e -> Alcotest.failf "encode: %s" (Json.Error.to_string e) 34 - | Ok json -> ( 35 - match Json.decode Qmp.Version.jsont json with 36 - | Ok v' -> 37 - Alcotest.(check int) "major" 9 v'.qemu.major; 38 - Alcotest.(check int) "minor" 0 v'.qemu.minor; 39 - Alcotest.(check int) "micro" 0 v'.qemu.micro; 40 - Alcotest.(check string) "package" "v9.0.0" v'.package 41 - | Error e -> Alcotest.failf "decode: %s" (Json.Error.to_string e)) 32 + let json = Json.encode Qmp.Version.jsont v in 33 + match Json.decode Qmp.Version.jsont json with 34 + | Ok v' -> 35 + Alcotest.(check int) "major" 9 v'.qemu.major; 36 + Alcotest.(check int) "minor" 0 v'.qemu.minor; 37 + Alcotest.(check int) "micro" 0 v'.qemu.micro; 38 + Alcotest.(check string) "package" "v9.0.0" v'.package 39 + | Error e -> Alcotest.failf "decode: %s" (Json.Error.to_string e) 42 40 43 41 let test_version_high_numbers () = 44 42 let v = Qmp.Version.make 99 12 3 "custom-build-2025" in