From 840228a10b84b7587cc40d1eb2a17d8586187f35 Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Wed, 2 Nov 2016 01:30:22 +0100 Subject: Don't crash in index.erl when index is invalid --- src/db.erl | 4 ++-- src/index.erl | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/db.erl b/src/db.erl index 85ed5d8..bf17e96 100644 --- a/src/db.erl +++ b/src/db.erl @@ -235,8 +235,8 @@ handle_call(stop, _From, State) -> {stop, normal, stopped, State}; handle_call({add_index_nosync_noreverse, {LeafHash, Index}}, _From, State) -> - ok = index:add_nosync(index_db, Index, LeafHash), - {reply, ok, State}. + Result = index:add_nosync(index_db, Index, LeafHash), + {reply, Result, State}. indexforhash_nosync(LeafHash, Index) -> ok = perm:addvalue(indexforhash_db, diff --git a/src/index.erl b/src/index.erl index fe47f59..5fe1dd6 100644 --- a/src/index.erl +++ b/src/index.erl @@ -95,8 +95,7 @@ add_internal(File, Index, Entry) when is_binary(Entry), size(Entry) == ?ENTRYSIZ Index * ?ENTRYSIZEINFILE < Position -> read; _ -> - util:exit_with_error(invalid, writefile, - "Index not valid") + {error, invalidindex} end, EntryText = hex:bin_to_hexstr(Entry) ++ "\n", case Mode of @@ -112,10 +111,10 @@ add_internal(File, Index, Entry) when is_binary(Entry), size(Entry) == ?ENTRYSIZ EntryText -> ok; _ -> - util:exit_with_error(invalid, writefile, - "Written content not the" ++ - " same as old content") - end + {error, invalidcontent} + end; + {error, Error} -> + {error, Error} end. -- cgit v1.1