Skip to content

Commit fb7772c

Browse files
committed
clean up, tests, version
1 parent 5aa7945 commit fb7772c

File tree

7 files changed

+35
-5
lines changed

7 files changed

+35
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## Version [v0.1.15] - 2025-08-28
6+
7+
### Fixed
8+
9+
* The `JuliaHub.upload_dataset` now correctly throws a `JuliaHubError` on certain backend errors. ([#103])
10+
511
## Version [v0.1.14] - 2025-06-11
612

713
### Added

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "JuliaHub"
22
uuid = "bc7fa6ce-b75e-4d60-89ad-56c957190b6e"
33
authors = ["JuliaHub Inc."]
4-
version = "0.1.14"
4+
version = "0.1.15"
55

66
[deps]
77
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

src/datasets.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,6 @@ function upload_dataset end
695695
# Any other 404 or other non-200 response indicates a backend failure
696696
_throw_invalidresponse(r)
697697
end
698-
_check_internal_error(r; var="POST /user/datasets/{name}/versions")
699698
upload_config = _check_dataset_upload_config(r, dtype; newly_created_dataset)
700699
# Upload the actual data
701700
try
@@ -794,7 +793,9 @@ function _new_dataset(
794793
end
795794

796795
function _open_dataset_version(auth::Authentication, name::AbstractString)::_RESTResponse
797-
_restcall(auth, :POST, "user", "datasets", name, "versions")
796+
r = _restcall(auth, :POST, "user", "datasets", name, "versions")
797+
_check_internal_error(r; var="POST /user/datasets/{name}/versions")
798+
return r
798799
end
799800

800801
function _upload_dataset(upload_config, local_path; progress::Bool)

src/projects.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ function upload_project_dataset(
241241
# Other response codes indicate a backend failure
242242
_throw_invalidresponse(r)
243243
end
244-
_check_internal_error(r; var="POST /user/datasets/{name}/versions")
245244
# ...
246245
upload_config = _check_dataset_upload_config(r, dtype; newly_created_dataset=false)
247246
# Upload the actual data
@@ -283,12 +282,14 @@ function _open_dataset_version(
283282
auth::Authentication, dataset_uuid::UUID, project_uuid::UUID
284283
)::_RESTResponse
285284
body = Dict("project" => string(project_uuid))
286-
return JuliaHub._restcall(
285+
r = JuliaHub._restcall(
287286
auth,
288287
:POST,
289288
("datasets", string(dataset_uuid), "versions"),
290289
JSON.json(body),
291290
)
291+
_check_internal_error(r; var="POST /user/datasets/{name}/versions")
292+
return r
292293
end
293294

294295
function _close_dataset_version(

test/datasets.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,13 @@ end
435435
@test_throws TypeError JuliaHub.upload_dataset(
436436
"example-dataset-license", @__FILE__; replace=true, license=(:fulltext, 1234)
437437
)
438+
439+
# Make sure we throw a JuliaHubError when we encounter an internal backend error
440+
# that gets reported over a 200.
441+
@test JuliaHub.upload_dataset("example-dataset-200-error-1", @__FILE__) isa JuliaHub.Dataset
442+
MOCK_JULIAHUB_STATE[:internal_error_200] = true
443+
@test_throws JuliaHub.JuliaHubError JuliaHub.upload_dataset("example-dataset-200-error", @__FILE__)
444+
MOCK_JULIAHUB_STATE[:internal_error_200] = false
438445
end
439446
empty!(MOCK_JULIAHUB_STATE)
440447
end

test/mocking.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ JuliaHub.__AUTH__[] = DEFAULT_GLOBAL_MOCK_AUTH
4646
Mocking.activate()
4747
const MOCK_JULIAHUB_STATE = Dict{Symbol, Any}()
4848
jsonresponse(status) = d -> JuliaHub._RESTResponse(status, JSON.json(d))
49+
function internal_error_200_response()
50+
d = Dict(
51+
"success" => false,
52+
"internal_error" => true,
53+
"message" => "Internal Server Error",
54+
)
55+
return JuliaHub._RESTResponse(200, JSON.json(d))
56+
end
4957
mocking_patch = [
5058
Mocking.@patch(
5159
JuliaHub._rest_request_mockable(args...; kwargs...) = _restcall_mocked(args...; kwargs...)
@@ -412,6 +420,9 @@ function _restcall_mocked(method, url, headers, payload; query)
412420
Dict("repo_id" => string(UUIDs.uuid4())) |> jsonresponse(200)
413421
end
414422
elseif (method == :POST) && endswith(url, DATASET_VERSIONS_REGEX)
423+
if get(MOCK_JULIAHUB_STATE, :internal_error_200, false)
424+
return internal_error_200_response()
425+
end
415426
dataset, is_user = let m = match(DATASET_VERSIONS_REGEX, url)
416427
URIs.unescapeuri(m[2]), m[1] == "user/"
417428
end

test/projects.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ end
243243
@test dataset.project.uuid === project_auth_2.project_id
244244
@test dataset.project.is_writable === false
245245
@test JuliaHub.upload_project_dataset(dataset_noproject, @__FILE__) isa JuliaHub.Dataset
246+
247+
MOCK_JULIAHUB_STATE[:internal_error_200] = true
248+
@test_throws JuliaHub.JuliaHubError JuliaHub.upload_project_dataset(dataset_noproject, @__FILE__)
249+
MOCK_JULIAHUB_STATE[:internal_error_200] = false
246250
end
247251
end
248252

0 commit comments

Comments
 (0)