diff --git a/src/batchimages.jl b/src/batchimages.jl index 94bf323fa..e9ade39ec 100644 --- a/src/batchimages.jl +++ b/src/batchimages.jl @@ -218,8 +218,9 @@ function _group_images(images; image_group::AbstractString) for image in images if !isa(image, Dict) msg = """ - Invalid JSON returned by the server: value for '$(image_group)' not an object - $(r_json_str) + Invalid JSON returned by the server: image value is not an object + image_group = $(image_group) + image = $(image) """ throw(JuliaHubError(msg)) end diff --git a/src/jobs/logging-legacy.jl b/src/jobs/logging-legacy.jl index 1f779e158..42eb4ff5c 100644 --- a/src/jobs/logging-legacy.jl +++ b/src/jobs/logging-legacy.jl @@ -493,7 +493,7 @@ end function _job_logs_legacy_start_streaming!(auth::Authentication, buffer::_LegacyLogsBuffer) if !isnothing(buffer._stream) - @warn "Logs are already being streamed" b._jobname + @warn "Logs are already being streamed" buffer._jobname return nothing end # If we're not already streaming, we construct a new _JobLogTask diff --git a/src/node.jl b/src/node.jl index b959c44f9..e4362051b 100644 --- a/src/node.jl +++ b/src/node.jl @@ -138,11 +138,11 @@ function nodespec( # in the other method; but it's valid to pass here too auth::Union{Authentication, Nothing}=nothing, ) - ncpu < 1 && throw(ArgumentError("ncpu must be >= 1")) - ngpu < 0 && throw(ArgumentError("ngpu must be >= 0")) - memory < 1 && throw(ArgumentError("memory must be >= 1")) + ncpu < 1 && Base.throw(ArgumentError("ncpu must be >= 1")) + ngpu < 0 && Base.throw(ArgumentError("ngpu must be >= 0")) + memory < 1 && Base.throw(ArgumentError("memory must be >= 1")) if ngpu >= 2 - return _throw_or_nothing(; msg="JuliaHub.jl does not support multi-GPU nodes", throw) do + return _throw_or_nothing(; msg="JuliaHub.jl does not support multi-GPU nodes", throw) do msg @warn msg end end diff --git a/src/utils.jl b/src/utils.jl index 329812b87..c5e4ddafb 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -360,7 +360,9 @@ end _nothing_or(f::Base.Callable, x) = isnothing(x) ? nothing : f(x) -# Helper function to handle the +# Helper function to help manage the pattern where a function takes a 'throw::Bool` keyword +# argument and should either throw an InvalidRequestError, or return nothing. +# # The nothrow_extra_logic_f(msg) callback can be used (via do syntax) do run additional code # before returning if throw=false. 'msg' is passed as the first argument. function _throw_or_nothing( diff --git a/test/jobs.jl b/test/jobs.jl index a268ef3a5..31fad39c9 100644 --- a/test/jobs.jl +++ b/test/jobs.jl @@ -133,6 +133,11 @@ end @test n.vcores == 2 @test n.mem == 8 end + + # Test the `throw` argument by requesting unsupported multi-GPU nodes + @test_throws JuliaHub.InvalidRequestError JuliaHub.nodespec(; ngpu=10) + @test_throws JuliaHub.InvalidRequestError JuliaHub.nodespec(; ngpu=10, throw=true) + @test @test_logs (:warn,) JuliaHub.nodespec(; ngpu=10, throw=false) === nothing end end