anchor.diff:    | UnexpectedJsonType (expected, got) -> wrap_js_failure qid expected got
   
   let read_interactive_query stream : query =
  +  match Util.read_line stream with
  +  | None -> exit 0
  +  | Some line ->
  +    match Util.json_of_string line with
  +    | None -> { qid = "?"; qq = ProtocolViolation "Json parsing failed." }
  +    | Some request -> safe_unpack_interactive_query request
  +
  +let safe_unpack_interactive_query js_query =
     try
  -    match Util.read_line stream with
  -    | None -> raise (ExitREPL 0)
  -    | Some line ->
  -      match Util.json_of_string line with
  -      | None -> { qid = "?"; qq = ProtocolViolation "Json parsing failed." }
  -      | Some request -> unpack_interactive_query request
  +    unpack_interactive_query js_query
     with
     | InvalidQuery msg -> { qid = "?"; qq = ProtocolViolation msg }
     | UnexpectedJsonType (expected, got) -> wrap_js_failure "?" expected got
  
positive.code:           { qid = q.qid; qq = GenericError "Current module unset" }
          | _ -> q
  
  let rec go st : int =
    let rec loop st : int =
      let query = validate_query st (read_interactive_query st.repl_stdin) in
      let (status, response), state_opt = run_query st query.qq in
      write_response query.qid status response;
      match state_opt with
      | Inl st' -> loop st'
      | Inr exitcode -> raise (ExitREPL exitcode) in
  
    if Options.trace_error () then
      loop st
    else
      try loop st with ExitREPL n -> n
  
  let interactive_error_handler = // No printing here — collect everything for future use
    let issues : ref<list<issue>> = Util.mk_ref [] in
  
negative.code:   Util.print_raw (Util.string_of_json json);
    Util.print_raw "\n"
  
  let json_of_response qid status response =
    let qid = JsonStr qid in
    let status = match status with
                 | QueryOK -> JsonStr "success"
                 | QueryNOK -> JsonStr "failure"
                 | QueryViolatesProtocol -> JsonStr "protocol-violation" in
    JsonAssoc [("kind", JsonStr "response");
               ("query-id", qid);
               ("status", status);
               ("response", response)]
  
  let write_response qid status response =
    write_json (json_of_response qid status response)
  
  let json_of_message level js_contents =
    JsonAssoc [("kind", JsonStr "message");
               ("level", JsonStr level);
               ("contents", js_contents)]
  
  let write_message level contents =
    write_json (json_of_message level contents)
  
  let json_of_hello =
    let js_version = JsonInt interactive_protocol_vernum in
    let js_features = JsonList (List.map JsonStr interactive_protocol_features) in
    JsonAssoc (("kind", JsonStr "protocol-info") :: alist_of_protocol_info)
  
  let write_hello () =
    write_json json_of_hello
  
  (*****************)
  (* Options cache *)
  