ocaml
0
fork

Configure Feed

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

Config_parser: return a result

+67 -56
+58 -47
bin/forester/main.ml
··· 40 40 41 41 let build ~env _ config_filename dev no_theme emit_legacy_xml = 42 42 Reporter.easy_run @@ fun () -> 43 - let config = Config_parser.parse_forest_config_file config_filename in 44 - let config = 45 - if dev then 46 - let doc_json_blob = List.hd Theme_site.Sites.docs ^ "/forest/docs.json" in 47 - { 48 - config with 49 - foreign = 50 - { 51 - path = doc_json_blob; 52 - route_locally = true; 53 - include_in_manifest = true; 54 - } 55 - :: config.foreign; 56 - } 57 - else config 58 - in 59 - Logs.debug (fun m -> m "Parsed config file %s" config_filename); 60 - let forest = Driver.batch_run ~env ~dev ~config in 61 - forest.diagnostics 62 - |> URI.Tbl.iter (fun _ d -> List.iter Reporter.Tty.display d); 63 - if not no_theme then begin 64 - let@ () = Reporter.trace "when copying theme directory" in 65 - let theme_dir = 66 - Option.value 67 - ~default:(List.hd Theme_site.Sites.themes ^ "/default") 68 - config.theme 43 + match Config_parser.parse_forest_config_file config_filename with 44 + | Error exn -> Logs.err (fun m -> m "%a" Eio.Exn.pp exn) 45 + | Ok config -> 46 + let config = 47 + if dev then 48 + let doc_json_blob = 49 + List.hd Theme_site.Sites.docs ^ "/forest/docs.json" 50 + in 51 + { 52 + config with 53 + foreign = 54 + { 55 + path = doc_json_blob; 56 + route_locally = true; 57 + include_in_manifest = true; 58 + } 59 + :: config.foreign; 60 + } 61 + else config 69 62 in 70 - Forester.copy_contents_of_dir ~env ~forest 71 - @@ Eio_util.path_of_dir ~env theme_dir 72 - end; 73 - Forester.render_forest ~dev ~forest ~emit_legacy_xml; 74 - Logs.app (fun m -> m "Success!") 63 + Logs.debug (fun m -> m "Parsed config file %s" config_filename); 64 + let forest = Driver.batch_run ~env ~dev ~config in 65 + forest.diagnostics 66 + |> URI.Tbl.iter (fun _ d -> List.iter Reporter.Tty.display d); 67 + if not no_theme then begin 68 + let@ () = Reporter.trace "when copying theme directory" in 69 + let theme_dir = 70 + Option.value 71 + ~default:(List.hd Theme_site.Sites.themes ^ "/default") 72 + config.theme 73 + in 74 + Forester.copy_contents_of_dir ~env ~forest 75 + @@ Eio_util.path_of_dir ~env theme_dir 76 + end; 77 + Forester.render_forest ~dev ~forest ~emit_legacy_xml; 78 + Logs.app (fun m -> m "Success!") 75 79 76 80 let new_tree ~env config_filename dest_dir prefix template random = 77 81 let@ () = Reporter.silence in 78 - let config = Config_parser.parse_forest_config_file config_filename in 79 - let forest = Driver.batch_run ~env ~dev:true ~config in 80 - let mode = if random then `Random else `Sequential in 81 - let new_tree = 82 - Forester.create_tree ~env ~dest_dir ~prefix ~template ~mode ~forest 83 - in 84 - Format.printf "%s@." new_tree 82 + match Config_parser.parse_forest_config_file config_filename with 83 + | Error exn -> Logs.err (fun m -> m "%a" Eio.Exn.pp exn) 84 + | Ok config -> 85 + let forest = Driver.batch_run ~env ~dev:true ~config in 86 + let mode = if random then `Random else `Sequential in 87 + let new_tree = 88 + Forester.create_tree ~env ~dest_dir ~prefix ~template ~mode ~forest 89 + in 90 + Format.printf "%s@." new_tree 85 91 86 92 let complete ~env config_filename title = 87 93 let@ () = Reporter.silence in 88 - let config = Config_parser.parse_forest_config_file config_filename in 89 - let forest = Driver.batch_run ~env ~dev:true ~config in 90 - let@ uri, title = List.iter @~ Forester.complete ~forest title in 91 - Format.printf "%s, %s\n" uri title 94 + match Config_parser.parse_forest_config_file config_filename with 95 + | Error exn -> Logs.err (fun m -> m "%a" Eio.Exn.pp exn) 96 + | Ok config -> 97 + let forest = Driver.batch_run ~env ~dev:true ~config in 98 + let@ uri, title = List.iter @~ Forester.complete ~forest title in 99 + Format.printf "%s, %s\n" uri title 92 100 93 101 let query_all ~env config_filename = 94 102 let@ () = Reporter.silence in 95 - let config = Config_parser.parse_forest_config_file config_filename in 96 - let forest = Driver.batch_run ~env ~config ~dev:true in 97 - Format.printf "%s" (Forester.json_manifest ~dev:true ~forest) 103 + match Config_parser.parse_forest_config_file config_filename with 104 + | Error exn -> Logs.err (fun m -> m "%a" Eio.Exn.pp exn) 105 + | Ok config -> 106 + let forest = Driver.batch_run ~env ~config ~dev:true in 107 + Format.printf "%s" (Forester.json_manifest ~dev:true ~forest) 98 108 99 109 let default_config_str = 100 110 {|[forest] ··· 285 295 Cmd.v info Term.(const (init ~env:env_) $ arg_dir) 286 296 287 297 let lsp ~env _ config = 288 - let config = Config_parser.parse_forest_config_file config in 289 - Forester_lsp.start ~env ~config 298 + match Config_parser.parse_forest_config_file config with 299 + | Error exn -> Logs.err (fun m -> m "%a" Eio.Exn.pp exn) 300 + | Ok config -> Forester_lsp.start ~env ~config 290 301 291 302 let lsp_cmd ~env:env_ = 292 303 let man =
+2 -4
lib/frontend/Config_parser.ml
··· 136 136 let lexbuf = Lexing.from_channel ch in 137 137 let result = parse lexbuf filename in 138 138 Sys.chdir @@ Filename.dirname filename; 139 - result 140 - with exn -> 141 - Reporter.fatal Configuration_error 142 - ~extra_remarks:[Asai.Diagnostic.loctextf "%a" Eio.Exn.pp exn] 139 + Ok result 140 + with exn -> Error exn
+1 -1
lib/frontend/Config_parser.mli
··· 7 7 open Forester_core 8 8 9 9 val parse_forest_config_string : string -> Config.t 10 - val parse_forest_config_file : string -> Config.t 10 + val parse_forest_config_file : string -> (Config.t, exn) result
+3 -3
lib/language_server/Change_configuration.ml
··· 18 18 | `Assoc xs -> begin 19 19 match List.assoc_opt "configuration_file" xs with 20 20 | Some (`String f) -> begin 21 - try 22 - let config = Config_parser.parse_forest_config_file f in 21 + match Config_parser.parse_forest_config_file f with 22 + | Ok config -> 23 23 Lsp_state.modify @@ fun state -> 24 24 {state with forest = {state.forest with config}} 25 - with _ -> Eio.traceln "failed to parse configuration file" 25 + | Error _ -> () 26 26 end 27 27 | _ -> Eio.traceln "invalid value for configuration_file" 28 28 (* RPC.Response.Error.raise *)
+3 -1
lib/search/Search_engine.ml
··· 59 59 Format.printf "got %i results@." (List.length results) 60 60 61 61 let main ~env () = 62 - let config = Config_parser.parse_forest_config_file "forest.toml" in 62 + let config = 63 + Result.get_ok @@ Config_parser.parse_forest_config_file "forest.toml" 64 + in 63 65 let dev = true in 64 66 let forest = Driver.batch_run ~env ~dev ~config in 65 67 let articles = List.of_seq @@ State.get_all_articles forest in