Skip to content

Commit 967396a

Browse files
authored
Merge pull request #598 from permaweb/feat/500_on_processing_message
Feat: Handling invalid messages in hb_store_gateway
2 parents cc6adc7 + 0b73eef commit 967396a

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/hb_ao.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,8 @@ ensure_message_loaded(MsgID, Opts) when ?IS_ID(MsgID) ->
846846
case hb_cache:read(MsgID, Opts) of
847847
{ok, LoadedMsg} ->
848848
LoadedMsg;
849+
failure ->
850+
failure;
849851
not_found ->
850852
throw({necessary_message_not_found, <<"/">>, MsgID})
851853
end;

src/hb_cache.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,14 @@ store_read(Target, Path, Store, Opts) ->
470470
{store, Store}
471471
}),
472472
case hb_store:type(Store, ResolvedFullPath) of
473+
failure -> failure;
473474
not_found -> not_found;
474475
simple ->
475476
?event({reading_data, ResolvedFullPath}),
476477
case hb_store:read(Store, ResolvedFullPath) of
477478
{ok, Bin} -> {ok, Bin};
478-
not_found -> not_found
479+
not_found -> not_found;
480+
failure -> failure
479481
end;
480482
composite ->
481483
?event({reading_composite, ResolvedFullPath}),

src/hb_store_gateway.erl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ list(StoreOpts, Key) ->
1313
?event(store_gateway, executing_list),
1414
case read(StoreOpts, Key) of
1515
not_found -> not_found;
16+
failure -> failure;
1617
{ok, Message} -> {ok, hb_maps:keys(Message, StoreOpts)}
1718
end.
1819

@@ -23,6 +24,7 @@ type(StoreOpts, Key) ->
2324
?event(store_gateway, executing_type),
2425
case read(StoreOpts, Key) of
2526
not_found -> not_found;
27+
failure -> failure;
2628
{ok, Data} ->
2729
?event({type, hb_private:reset(hb_message:uncommitted(Data, StoreOpts))}),
2830
IsFlat = lists:all(
@@ -60,14 +62,24 @@ read(BaseStoreOpts, Key) ->
6062
case hb_store_remote_node:read_local_cache(StoreOpts, ID) of
6163
not_found ->
6264
?event({gateway_read, {opts, StoreOpts}, {id, ID}, {subpath, Rest}}),
63-
case hb_gateway_client:read(ID, StoreOpts) of
65+
try hb_gateway_client:read(ID, StoreOpts) of
6466
{error, _} ->
6567
?event({read_not_found, {key, ID}}),
6668
not_found;
6769
{ok, Message} ->
6870
?event({read_found, {key, ID}}),
6971
hb_store_remote_node:maybe_cache(StoreOpts, Message),
7072
extract_path_value(Message, Rest, StoreOpts)
73+
catch Class:Reason:Stacktrace ->
74+
?event(
75+
gateway,
76+
{read_failed,
77+
{class, Class},
78+
{reason, Reason},
79+
{stacktrace, {trace, Stacktrace}}
80+
}
81+
),
82+
failure
7183
end;
7284
{ok, CachedMessage} ->
7385
extract_path_value(CachedMessage, Rest, StoreOpts)
@@ -463,6 +475,23 @@ verifiability_test() ->
463475
?event({verifying, {structured, Structured}, {original, Message}}),
464476
?assert(hb_message:verify(Structured)).
465477

478+
%% @doc Reading an unsupported signature type transaction should fail
479+
failure_to_process_message_test() ->
480+
hb_http_server:start_node(#{}),
481+
?assertEqual(failure,
482+
hb_cache:read(
483+
<<"j0_mJMXG2YO4oRcOtjYsNoUJbN2TaKLo4nTtbhKqnEU">>,
484+
#{
485+
store =>
486+
[
487+
#{
488+
<<"store-module">> => hb_store_gateway
489+
}
490+
]
491+
}
492+
)
493+
).
494+
466495
%% @doc Test that another HyperBEAM node offering the `~query@1.0' device can
467496
%% be used as a store.
468497
remote_hyperbeam_node_ans104_test() ->

0 commit comments

Comments
 (0)