Skip to content

Commit 35a65b6

Browse files
committed
don't try to load state from file on startup if doesn't exist
1 parent 7ff33c9 commit 35a65b6

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lib/context.ml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ let refresh_state ctx =
7474
match ctx.state_filepath with
7575
| None -> Ok ctx
7676
| Some path ->
77-
log#info "loading saved state from file %s" path;
78-
( match get_local_file path with
79-
| Error e -> fmt_error "error while getting local file: %s\nfailed to get state from file %s" e path
80-
| Ok file ->
81-
let state = State_j.state_of_string file in
82-
Ok { ctx with state }
83-
)
77+
if Caml.Sys.file_exists path then begin
78+
log#info "loading saved state from file %s" path;
79+
match get_local_file path with
80+
| Error e -> fmt_error "error while getting local file: %s\nfailed to get state from file %s" e path
81+
| Ok file ->
82+
let state = State_j.state_of_string file in
83+
Ok { ctx with state }
84+
end
85+
else Ok ctx
8486

8587
let print_config ctx =
8688
let cfg = get_config_exn ctx in

src/notabot.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ let secrets =
7373

7474
let state =
7575
let doc = "state file" in
76-
Arg.(value & opt (some file) None & info [ "state" ] ~docv:"STATE" ~doc)
76+
Arg.(value & opt (some string) None & info [ "state" ] ~docv:"STATE" ~doc)
7777

7878
let gh_payload =
7979
let doc = "JSON file containing a github webhook payload" in

0 commit comments

Comments
 (0)