···40404141let build ~env _ config_filename dev no_theme emit_legacy_xml =
4242 Reporter.easy_run @@ fun () ->
4343- let config = Config_parser.parse_forest_config_file config_filename in
4444- let config =
4545- if dev then
4646- let doc_json_blob = List.hd Theme_site.Sites.docs ^ "/forest/docs.json" in
4747- {
4848- config with
4949- foreign =
5050- {
5151- path = doc_json_blob;
5252- route_locally = true;
5353- include_in_manifest = true;
5454- }
5555- :: config.foreign;
5656- }
5757- else config
5858- in
5959- Logs.debug (fun m -> m "Parsed config file %s" config_filename);
6060- let forest = Driver.batch_run ~env ~dev ~config in
6161- forest.diagnostics
6262- |> URI.Tbl.iter (fun _ d -> List.iter Reporter.Tty.display d);
6363- if not no_theme then begin
6464- let@ () = Reporter.trace "when copying theme directory" in
6565- let theme_dir =
6666- Option.value
6767- ~default:(List.hd Theme_site.Sites.themes ^ "/default")
6868- config.theme
4343+ match Config_parser.parse_forest_config_file config_filename with
4444+ | Error exn -> Logs.err (fun m -> m "%a" Eio.Exn.pp exn)
4545+ | Ok config ->
4646+ let config =
4747+ if dev then
4848+ let doc_json_blob =
4949+ List.hd Theme_site.Sites.docs ^ "/forest/docs.json"
5050+ in
5151+ {
5252+ config with
5353+ foreign =
5454+ {
5555+ path = doc_json_blob;
5656+ route_locally = true;
5757+ include_in_manifest = true;
5858+ }
5959+ :: config.foreign;
6060+ }
6161+ else config
6962 in
7070- Forester.copy_contents_of_dir ~env ~forest
7171- @@ Eio_util.path_of_dir ~env theme_dir
7272- end;
7373- Forester.render_forest ~dev ~forest ~emit_legacy_xml;
7474- Logs.app (fun m -> m "Success!")
6363+ Logs.debug (fun m -> m "Parsed config file %s" config_filename);
6464+ let forest = Driver.batch_run ~env ~dev ~config in
6565+ forest.diagnostics
6666+ |> URI.Tbl.iter (fun _ d -> List.iter Reporter.Tty.display d);
6767+ if not no_theme then begin
6868+ let@ () = Reporter.trace "when copying theme directory" in
6969+ let theme_dir =
7070+ Option.value
7171+ ~default:(List.hd Theme_site.Sites.themes ^ "/default")
7272+ config.theme
7373+ in
7474+ Forester.copy_contents_of_dir ~env ~forest
7575+ @@ Eio_util.path_of_dir ~env theme_dir
7676+ end;
7777+ Forester.render_forest ~dev ~forest ~emit_legacy_xml;
7878+ Logs.app (fun m -> m "Success!")
75797680let new_tree ~env config_filename dest_dir prefix template random =
7781 let@ () = Reporter.silence in
7878- let config = Config_parser.parse_forest_config_file config_filename in
7979- let forest = Driver.batch_run ~env ~dev:true ~config in
8080- let mode = if random then `Random else `Sequential in
8181- let new_tree =
8282- Forester.create_tree ~env ~dest_dir ~prefix ~template ~mode ~forest
8383- in
8484- Format.printf "%s@." new_tree
8282+ match Config_parser.parse_forest_config_file config_filename with
8383+ | Error exn -> Logs.err (fun m -> m "%a" Eio.Exn.pp exn)
8484+ | Ok config ->
8585+ let forest = Driver.batch_run ~env ~dev:true ~config in
8686+ let mode = if random then `Random else `Sequential in
8787+ let new_tree =
8888+ Forester.create_tree ~env ~dest_dir ~prefix ~template ~mode ~forest
8989+ in
9090+ Format.printf "%s@." new_tree
85918692let complete ~env config_filename title =
8793 let@ () = Reporter.silence in
8888- let config = Config_parser.parse_forest_config_file config_filename in
8989- let forest = Driver.batch_run ~env ~dev:true ~config in
9090- let@ uri, title = List.iter @~ Forester.complete ~forest title in
9191- Format.printf "%s, %s\n" uri title
9494+ match Config_parser.parse_forest_config_file config_filename with
9595+ | Error exn -> Logs.err (fun m -> m "%a" Eio.Exn.pp exn)
9696+ | Ok config ->
9797+ let forest = Driver.batch_run ~env ~dev:true ~config in
9898+ let@ uri, title = List.iter @~ Forester.complete ~forest title in
9999+ Format.printf "%s, %s\n" uri title
9210093101let query_all ~env config_filename =
94102 let@ () = Reporter.silence in
9595- let config = Config_parser.parse_forest_config_file config_filename in
9696- let forest = Driver.batch_run ~env ~config ~dev:true in
9797- Format.printf "%s" (Forester.json_manifest ~dev:true ~forest)
103103+ match Config_parser.parse_forest_config_file config_filename with
104104+ | Error exn -> Logs.err (fun m -> m "%a" Eio.Exn.pp exn)
105105+ | Ok config ->
106106+ let forest = Driver.batch_run ~env ~config ~dev:true in
107107+ Format.printf "%s" (Forester.json_manifest ~dev:true ~forest)
9810899109let default_config_str =
100110 {|[forest]
···285295 Cmd.v info Term.(const (init ~env:env_) $ arg_dir)
286296287297let lsp ~env _ config =
288288- let config = Config_parser.parse_forest_config_file config in
289289- Forester_lsp.start ~env ~config
298298+ match Config_parser.parse_forest_config_file config with
299299+ | Error exn -> Logs.err (fun m -> m "%a" Eio.Exn.pp exn)
300300+ | Ok config -> Forester_lsp.start ~env ~config
290301291302let lsp_cmd ~env:env_ =
292303 let man =
+2-4
lib/frontend/Config_parser.ml
···136136 let lexbuf = Lexing.from_channel ch in
137137 let result = parse lexbuf filename in
138138 Sys.chdir @@ Filename.dirname filename;
139139- result
140140- with exn ->
141141- Reporter.fatal Configuration_error
142142- ~extra_remarks:[Asai.Diagnostic.loctextf "%a" Eio.Exn.pp exn]
139139+ Ok result
140140+ with exn -> Error exn
···1818 | `Assoc xs -> begin
1919 match List.assoc_opt "configuration_file" xs with
2020 | Some (`String f) -> begin
2121- try
2222- let config = Config_parser.parse_forest_config_file f in
2121+ match Config_parser.parse_forest_config_file f with
2222+ | Ok config ->
2323 Lsp_state.modify @@ fun state ->
2424 {state with forest = {state.forest with config}}
2525- with _ -> Eio.traceln "failed to parse configuration file"
2525+ | Error _ -> ()
2626 end
2727 | _ -> Eio.traceln "invalid value for configuration_file"
2828 (* RPC.Response.Error.raise *)
+3-1
lib/search/Search_engine.ml
···5959 Format.printf "got %i results@." (List.length results)
60606161let main ~env () =
6262- let config = Config_parser.parse_forest_config_file "forest.toml" in
6262+ let config =
6363+ Result.get_ok @@ Config_parser.parse_forest_config_file "forest.toml"
6464+ in
6365 let dev = true in
6466 let forest = Driver.batch_run ~env ~dev ~config in
6567 let articles = List.of_seq @@ State.get_all_articles forest in