diff options
author | Magnus Ahltorp <map@kth.se> | 2016-11-02 01:30:22 +0100 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2016-11-02 01:30:22 +0100 |
commit | 840228a10b84b7587cc40d1eb2a17d8586187f35 (patch) | |
tree | 47861093048eda5f0f8d93e2fa8d45e3590cafc6 | |
parent | e51588399d15cde7ee283e1f72f99ddefa60f83d (diff) |
Don't crash in index.erl when index is invalid
-rw-r--r-- | src/db.erl | 4 | ||||
-rw-r--r-- | src/index.erl | 11 |
2 files changed, 7 insertions, 8 deletions
@@ -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. |