Factory Sensors - error messages I don't understand

Bonjour!

I started this exercise yesterday and almost solved - it works in the REPL - but not in Exercism.
and there are error messages I don’t understand

can anyone be of any help, please:

monitor the machine - passing
Code Run

@test machinemonitor(53, 200)

Test Error

AssertionError: !(isempty(msg_h)) || !(isempty(msg_t))
Stacktrace:
  [1] machinemonitor(pct_humidity::Int64, temperature::Int64)
    @ ExercismTestReports ./factory-sensors.jl:67
  [2] (::ExercismTestReports.var"#19#20")()
    @ ExercismTestReports ./none:-1
  [3] with_logstate(f::ExercismTestReports.var"#19#20", logstate::Base.CoreLogging.LogState)
    @ Base.CoreLogging ./logging/logging.jl:542
  [4] with_logger(f::Function, logger::Test.TestLogger)
    @ Base.CoreLogging ./logging/logging.jl:653
  [5] #collect_test_logs#50
    @ /usr/local/julia/share/julia/stdlib/v1.12/Test/src/logging.jl:126 [inlined]
  [6] collect_test_logs
    @ /usr/local/julia/share/julia/stdlib/v1.12/Test/src/logging.jl:124 [inlined]
  [7] match_logs(::Function, ::Tuple{Symbol, String}, ::Vararg{Tuple{Symbol, String}}; match_mode::Symbol, kwargs::@Kwargs{})
    @ Test /usr/local/julia/share/julia/stdlib/v1.12/Test/src/logging.jl:274
  [8] match_logs(::Function, ::Tuple{Symbol, String}, ::Vararg{Tuple{Symbol, String}})
    @ Test /usr/local/julia/share/julia/stdlib/v1.12/Test/src/logging.jl:273
  [9] top-level scope
    @ ./runtests.jl:6
 [10] macro expansion
    @ /usr/local/julia/share/julia/stdlib/v1.12/Test/src/Test.jl:1776 [inlined]
 [11] macro expansion
    @ ./runtests.jl:34 [inlined]
 [12] macro expansion
    @ /usr/local/julia/share/julia/stdlib/v1.12/Test/src/Test.jl:1776 [inlined]
 [13] macro expansion
    @ ./runtests.jl:35 [inlined]
 [14] macro expansion
    @ /usr/local/julia/share/julia/stdlib/v1.12/Test/src/Test.jl:1776 [inlined]
 [15] macro expansion
    @ ./runtests.jl:35 [inlined]

monitor the machine - failing
Code Run

@test_throws ExercismTestReports.MachineError machinemonitor(52, nothing)

Test Failure

Test Failed at ./runtests.jl:43
  Expression: machinemonitor(52, nothing)
    Expected: ExercismTestReports.MachineError
      Thrown: AssertionError
      AssertionError: !(isempty(msg_h)) || !(isempty(msg_t))
      Stacktrace:
       [1] machinemonitor(pct_humidity::Int64, temperature::Nothing)
         @ ExercismTestReports ./factory-sensors.jl:67
       [2] macro expansion
         @ ./runtests.jl:43 [inlined]
       [3] macro expansion
         @ /usr/local/julia/share/julia/stdlib/v1.12/Test/src/Test.jl:774 [inlined]
       [4] (::ExercismTestReports.var"#23#24")()
         @ ExercismTestReports ./none:0


thanks for any help in advance,

Nisang

maybe it’s good to add some code:

function machinemonitor(pct_humidity, temperature)
    msg_h = msg_t = ""
    log_h = log_t = ""
    try
        log_h = humiditycheck(pct_humidity)
    catch problem
        if problem isa ErrorException # number out of range
#           add Error log:
            @error("humidity level check failed: $pct_humidity%")
            msg_h = "humidity level check failed: $pct_humidity%"
        end
    end
    try
        log_t = temperaturecheck(temperature)
    catch problem
        if problem isa ArgumentError # number out of range
#           add Warn log:
            @warn("sensor is broken")
        elseif problem isa DomainError # number out of range
#           add Error log:
            @error("overheating detected: $temperature °C")
            msg_t = "overheating detected: $temperature °C"
        elseif problem isa MethodError # no idea what n is
            @error "please supply a valid argument"
        else
            rethrow() # the error could be anything else
        end
    end
#    if !isempty(msg_h) || !isempty(msg_t)
    @assert !isempty(msg_h) || !isempty(msg_t)
#       any Error? throw MachineError
#        @show "checks failed:"
        throw(MachineError(msg_h * " " * msg_t, 0))
#    end
    @info log_h * " " * log_t 
end

From what I can see, your code is throwing an error due to your line:

@assert does not work like an if clause, unless you use it in a try-catch block.

So your code threw an AssertionError, and the test was not expecting an AssertionError as the answer. This is the case for both of your Test Failure messages.

As for the error messages:

  1. The first failure message is because your code threw an error when one was not expected, so the test was not evaluated.
  2. The second test was expecting an error (MachineError), but your code threw the wrong type of error (AssertionError). This failure message is more informative because the test was expecting an error, so it was evaluated: