more house keeping

This commit is contained in:
2026-02-21 20:50:14 -05:00
parent 47eefd0fe5
commit 5ee3df86f1
5 changed files with 129 additions and 47 deletions

View File

@@ -421,12 +421,21 @@ handle_put_item :: proc(engine: ^dynamodb.Storage_Engine, request: ^HTTP_Request
// If no explicit Key field, extract key from Item
// (PutItem doesn't have a Key field — the key is in the Item itself)
existing_maybe, get_err := dynamodb.get_item(engine, table_name, item)
if get_err != .None && get_err != .Table_Not_Found {
// Table not found is handled by put_item below
if get_err == .Missing_Key_Attribute || get_err == .Invalid_Key {
#partial switch get_err {
case .None:
// Item found or not found — both are fine, condition evaluates against
// whatever was returned (nil item = item doesn't exist).
case .Table_Not_Found:
// Table will be caught and reported properly by put_item below.
case .Missing_Key_Attribute, .Invalid_Key:
handle_storage_error(response, get_err)
return
}
case .RocksDB_Error, .Serialization_Error, .Internal_Error:
make_error_response(response, .InternalServerError, "Failed to fetch existing item")
return
case .Validation_Error, .Item_Not_Found:
// Item_Not_Found shouldn't reach here (get_item returns nil, .None),
// but treat defensively.
}
existing_item = existing_maybe
} else {
@@ -566,11 +575,19 @@ handle_delete_item :: proc(engine: ^dynamodb.Storage_Engine, request: ^HTTP_Requ
// Fetch existing item
existing_item, get_err := dynamodb.get_item(engine, table_name, key)
if get_err != .None && get_err != .Table_Not_Found {
if get_err == .Missing_Key_Attribute || get_err == .Invalid_Key {
#partial switch get_err {
case .None:
// Item found or not found — condition evaluates against whatever was returned.
case .Table_Not_Found:
// Table will be caught and reported properly by delete_item below.
case .Missing_Key_Attribute, .Invalid_Key:
handle_storage_error(response, get_err)
return
}
case .RocksDB_Error, .Serialization_Error, .Internal_Error:
make_error_response(response, .InternalServerError, "Failed to fetch existing item")
return
case .Validation_Error, .Item_Not_Found:
// Defensive — shouldn't reach here normally.
}
defer {
if ex, has_ex := existing_item.?; has_ex {
@@ -1202,11 +1219,15 @@ handle_query :: proc(engine: ^dynamodb.Storage_Engine, request: ^HTTP_Request, r
}
// Parse ExclusiveStartKey
exclusive_start_key, esk_ok := dynamodb.parse_exclusive_start_key(
exclusive_start_key, esk_ok, esk_body_err := dynamodb.parse_exclusive_start_key(
request.body, table_name, metadata.key_schema,
)
if !esk_ok {
make_error_response(response, .ValidationException, "Invalid ExclusiveStartKey")
if esk_body_err {
make_error_response(response, .SerializationException, "Request body is not valid JSON")
} else {
make_error_response(response, .ValidationException, "Invalid ExclusiveStartKey")
}
return
}
defer {
@@ -1257,11 +1278,15 @@ handle_query :: proc(engine: ^dynamodb.Storage_Engine, request: ^HTTP_Request, r
return
}
esk_gsi, esk_gsi_ok := dynamodb.parse_exclusive_start_key_gsi(
esk_gsi, esk_gsi_ok, esk_gsi_body_err := dynamodb.parse_exclusive_start_key_gsi(
request.body, table_name, &metadata, gsi,
)
if !esk_gsi_ok {
make_error_response(response, .ValidationException, "Invalid ExclusiveStartKey")
if esk_gsi_body_err {
make_error_response(response, .SerializationException, "Request body is not valid JSON")
} else {
make_error_response(response, .ValidationException, "Invalid ExclusiveStartKey")
}
return
}
defer {
@@ -1402,11 +1427,15 @@ handle_scan :: proc(engine: ^dynamodb.Storage_Engine, request: ^HTTP_Request, re
limit = 100
}
exclusive_start_key, esk_ok := dynamodb.parse_exclusive_start_key(
exclusive_start_key, esk_ok, esk_body_err := dynamodb.parse_exclusive_start_key(
request.body, table_name, metadata.key_schema,
)
if !esk_ok {
make_error_response(response, .ValidationException, "Invalid ExclusiveStartKey")
if esk_body_err {
make_error_response(response, .SerializationException, "Request body is not valid JSON")
} else {
make_error_response(response, .ValidationException, "Invalid ExclusiveStartKey")
}
return
}
defer {
@@ -1451,11 +1480,15 @@ handle_scan :: proc(engine: ^dynamodb.Storage_Engine, request: ^HTTP_Request, re
return
}
esk_gsi, esk_gsi_ok := dynamodb.parse_exclusive_start_key_gsi(
esk_gsi, esk_gsi_ok, esk_gsi_body_err := dynamodb.parse_exclusive_start_key_gsi(
request.body, table_name, &metadata, gsi,
)
if !esk_gsi_ok {
make_error_response(response, .ValidationException, "Invalid ExclusiveStartKey")
if esk_gsi_body_err {
make_error_response(response, .SerializationException, "Request body is not valid JSON")
} else {
make_error_response(response, .ValidationException, "Invalid ExclusiveStartKey")
}
return
}
defer {