Skip to content
Snippets Groups Projects
Commit 8c05bf53 authored by florian's avatar florian
Browse files

ENH: Add logging messages for return codes <0

parent 78f93340
No related branches found
No related tags found
1 merge request!4ENH: Add minimal functionality
Pipeline #10970 passed
Pipeline: CaosDB Julia Integration Tests

#10971

    ...@@ -31,8 +31,9 @@ library_name = (@static Sys.iswindows() ? "ccaosdb" : "libccaosdb") ...@@ -31,8 +31,9 @@ library_name = (@static Sys.iswindows() ? "ccaosdb" : "libccaosdb")
    module Exceptions module Exceptions
    export evaluate_return_code, CaosDBException, GenericCaosDBException export evaluate_return_code, CaosDBException, GenericCaosDBException, CaosDBMessage
    using Logging
    using CaosDB using CaosDB
    """ """
    ...@@ -50,7 +51,19 @@ struct GenericCaosDBException <: CaosDBException ...@@ -50,7 +51,19 @@ struct GenericCaosDBException <: CaosDBException
    code::Cint code::Cint
    end end
    Base.showerror(io::IO, e::CaosDBException) = print(io, "CaosDBException: ", e.msg) Base.showerror(io::IO, e::CaosDBException) =
    print(io, "CaosDBException: ", e.msg, " (Status code ", e.code, ")")
    """
    Struct containing Messages and codes for status codes<0 that do not
    correspond to errors or success.
    """
    struct CaosDBMessage
    msg::String
    code::Cint
    end
    Base.show(io::IO, m::CaosDBMessage) = print(io, m.msg, " (Status code ", m.code, ")")
    """ """
    function evaluate_return_code(code::Cint) function evaluate_return_code(code::Cint)
    ...@@ -66,7 +79,11 @@ function evaluate_return_code(code::Cint) ...@@ -66,7 +79,11 @@ function evaluate_return_code(code::Cint)
    (Cint,), (Cint,),
    code, code,
    ) )
    throw(GenericCaosDBException(unsafe_string(msg), code)) if code > 0
    throw(GenericCaosDBException(unsafe_string(msg), code))
    else
    @info CaosDBMessage(unsafe_string(msg), code)
    end
    end end
    end end
    ...@@ -180,7 +197,7 @@ function create_plain_password_authenticator( ...@@ -180,7 +197,7 @@ function create_plain_password_authenticator(
    password, password,
    ) )
    CaosDB.Excepions.evaluate_return_code(err_code) CaosDB.Exceptions.evaluate_return_code(err_code)
    return auth return auth
    ......
    ...@@ -134,7 +134,7 @@ function create_pem_file_certificate_provider(path::AbstractString) ...@@ -134,7 +134,7 @@ function create_pem_file_certificate_provider(path::AbstractString)
    path, path,
    ) )
    CaosDB.Excepions.evaluate_return_code(err_code) CaosDB.Exceptions.evaluate_return_code(err_code)
    return cert_provider return cert_provider
    ...@@ -176,7 +176,7 @@ function create_tls_connection_configuration( ...@@ -176,7 +176,7 @@ function create_tls_connection_configuration(
    provider, provider,
    ) )
    CaosDB.Excepions.evaluate_return_code(err_code) CaosDB.Exceptions.evaluate_return_code(err_code)
    return config return config
    ...@@ -195,7 +195,7 @@ function create_insecure_connection_configuration(host::AbstractString, port::Ci ...@@ -195,7 +195,7 @@ function create_insecure_connection_configuration(host::AbstractString, port::Ci
    port, port,
    ) )
    CaosDB.Excepions.evaluate_return_code(err_code) CaosDB.Exceptions.evaluate_return_code(err_code)
    return config return config
    end end
    ...@@ -217,7 +217,7 @@ function create_connection(config::Ref{_Configuration}) ...@@ -217,7 +217,7 @@ function create_connection(config::Ref{_Configuration})
    config, config,
    ) )
    CaosDB.Excepions.evaluate_return_code(err_code) CaosDB.Exceptions.evaluate_return_code(err_code)
    return connection return connection
    ...@@ -248,7 +248,7 @@ function get_connection(name::AbstractString = "default") ...@@ -248,7 +248,7 @@ function get_connection(name::AbstractString = "default")
    ) )
    end end
    CaosDB.Excepions.evaluate_return_code(err_code) CaosDB.Exceptions.evaluate_return_code(err_code)
    return connection return connection
    ...@@ -273,7 +273,7 @@ function get_version_info(con::Ref{_Connection}) ...@@ -273,7 +273,7 @@ function get_version_info(con::Ref{_Connection})
    con, con,
    ) )
    CaosDB.Excepions.evaluate_return_code(err_code) CaosDB.Exceptions.evaluate_return_code(err_code)
    return info return info
    ......
    ...@@ -34,12 +34,34 @@ using CaosDB ...@@ -34,12 +34,34 @@ using CaosDB
    end end
    @testset "TestExceptions" begin @testset "TestExceptions" begin
    # In case of success, nothing is done
    @test CaosDB.Exceptions.evaluate_return_code(Cint(0)) == nothing @test CaosDB.Exceptions.evaluate_return_code(Cint(0)) == nothing
    # CaosDBExceptions are thrown for return codes > 0
    @test_throws CaosDB.Exceptions.CaosDBException CaosDB.Exceptions.evaluate_return_code( @test_throws CaosDB.Exceptions.CaosDBException CaosDB.Exceptions.evaluate_return_code(
    Cint(14), Cint(14),
    ) )
    @test_throws CaosDB.Exceptions.GenericCaosDBException CaosDB.Exceptions.evaluate_return_code( @test_throws CaosDB.Exceptions.GenericCaosDBException CaosDB.Exceptions.evaluate_return_code(
    Cint(14), Cint(14),
    ) )
    try
    CaosDB.Exceptions.evaluate_return_code(Cint(14))
    # fail if this doesn't throw an error
    @test false
    catch e
    @test isa(e, CaosDB.Exceptions.GenericCaosDBException)
    @test e.code == 14
    end
    # Return codes < 0 correspond to unfinished transactions and
    # we expect messages to be returned.
    @test CaosDB.Exceptions.evaluate_return_code(Cint(-1)) == nothing
    @test_logs (
    :info,
    CaosDB.Exceptions.CaosDBMessage(
    "The transaction is currently being executed.",
    Cint(-1),
    ),
    ) CaosDB.Exceptions.evaluate_return_code(Cint(-1))
    end end
    end end
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment