Every error that condathis raises has the class condathis_error, and
every warning has the class condathis_warning. Each condition also has
more specific classes. Use them to handle one kind of problem with
base::tryCatch(), base::withCallingHandlers() or
rlang::try_fetch(), and to test for it with
testthat::expect_error(class = ). Do not match the text of a message:
it can change in any release.
The class scheme
The classes of a condition go from the most specific to the most general:
The class of the function and the problem,
condathis_<function>_<problem>, with the full name of the exported function. For example,condathis_create_env_existsorcondathis_run_bin_env_not_found.Older names of that class, kept so that existing handlers still work (see Renamed classes). Some classes carry further names that this page does not list: do not rely on them.
Shared classes for the kind of problem, for example
condathis_invalid_overwriteandcondathis_invalid_arg, orcondathis_env_not_found.The root class,
condathis_errororcondathis_warning.
The rlang package adds its own classes after these, such as
rlang_error, error and condition.
For example, create_env(overwrite = "yes") aborts with the classes
c("condathis_create_env_invalid_overwrite", "condathis_create_invalid_overwrite_arg", "condathis_invalid_overwrite", "condathis_invalid_arg", "condathis_error").
The checks of verbose, method and error are the same in every
function, so their errors have only shared classes, for example
c("condathis_invalid_verbose", "condathis_invalid_arg", "condathis_error").
Handle the most general class that fits. A handler for
condathis_env_not_found catches a missing environment in every
function, and a handler for condathis_error catches every error of
condathis.
Shared classes
condathis_invalid_arg: an argument has an invalid value.condathischecks the arguments before it changes anything, so such an error has no side effects.condathis_invalid_<argument>: an invalid value of one argument, with its exact name. For example,condathis_invalid_env_name,condathis_invalid_packages,condathis_invalid_channels,condathis_invalid_method,condathis_invalid_verbose,condathis_invalid_errororcondathis_invalid_timeout. It always comes withcondathis_invalid_arg.condathis_parse_match_spec_invalid_nameandcondathis_parse_match_spec_invalid_url: a package spec that condathis cannot read, such as"::", or the URL of a package file whose name is not<name>-<version>-<build>.condathisreads the specs when it compares them with an existing environment, increate_env(),install_packages()andvalidate_env(). Alsocondathis_invalid_arg.condathis_env_not_found: the environment does not exist. Onlyrun(),run_bin(),run_pipeline()andinstall_packages()create a missing environment, and only the default"condathis-env". Witherror = "continue", the run family returns status 127 instead. When the environment is in the data directory of a backend whose package cannot be used (seecondathis_backend_not_installed), the message names that backend.condathis_backend_error: a backend failed. The function classes arecondathis_<function>_failed,condathis_<function>_resolve_failed(a command or its activation could not be resolved) andcondathis_backend_probe_failed. The backend's error is the parent, sorlang::cnd_inherits()finds its classes. Thecondathis_*classes of the backend's error are also copied, for examplecondathis_micromamba_status_error.condathis_backend_probe_failed: a backend could not tell whether the environment exists.create_env(),install_packages()andremove_env()then stop before they change anything. Alsocondathis_backend_error.condathis_backend_query_failed(a warning): withmethod = "auto", a query of one backend failed, and the function skipped that backend.condathis_backend_invalid_return: a backend returned a value that breaks the contract ofregister_backend(). The message names the backend. Alsocondathis_backend_contract_violation. For the value ofbackend_resolve_run(), the first class iscondathis_backend_resolve_run_invalid.condathis_backend_contract_violation: a backend breaks the contract, when it is registered or in a return value.condathis_backend_not_installed: the package of a backend that condathis knows, such as"rattler"of therattlerthispackage, is not installed. An error whenmethodnames that backend (with the classes of an invalidmethod). Also an error when a call would change an environment in the data directory of that backend (withcondathis_backend_mismatch). A warning when a query skips the environments of that backend (once per session). Also a warning whenclean_cache()cannot clean its caches.condathis_backend_load_failed: the same, when the package is installed but failed to load, did not register its backend, or its backend was unregistered in this session. The error of the load is the parent. Also a warning, once per session, whencondathistried to load the package. It tries this when its backend has environments or caches, or when the optioncondathis.backend_prioritynames it.condathis_link_scripts_skipped(a warning): the backend did not run the pre-link, post-link or pre-unlink scripts of some packages, which micromamba runs, so these packages may not work. The call itself succeeded. The warning has the fieldsbackend,env_name,packages(the package names, sorted) andscripts(a data frame with the columnspackageandscript).condathis_backend_quiesce_failed(a warning):with_sandbox_dir()orclean_cache()could not tell whether a backend still works in the R process, and went on.condathis_env_lock_waiting(a message, neither an error nor a warning):create_env(),install_packages()orremove_env()waits for another R session that changes the same environment (see Other R sessions increate_env()).condathis_cache_lock_waiting(a message):clean_cache()waits for other R sessions that create environments or install packages, or these wait for aclean_cache()of another session.condathis_env_lock_unavailable(a warning, once per session): the lock of the environment or of the package caches could not be taken, for example on a file system that cannot lock files. The call went on without it.condathis_status_error: a command ofrun(),run_bin()orrun_pipeline()exited with a status other than 0.condathis_timeout_error: a command ofrun(),run_bin()orrun_pipeline()ran longer thantimeoutand was killed.condathis_micromamba_status_error: amicromambacommand that condathis started for the micromamba backend failed. It carries the fieldsstatusandstderr, also when it is the class of a backend failure that condathis re-raised.Deprecated arguments and values, which still work but will be removed (warnings).
condathis_deprecated_packages_argis forpackages =increate_env(),install_packages()andvalidate_env()(once per session and function).condathis_deprecated_method_nativeis formethod = "native"(once per session).condathis_deprecated_argis fortimeout_limitininstall_micromamba().
Error fields
The status and timeout errors of run(), run_bin() and
run_pipeline() carry these fields, so a handler does not need to read
the message:
status: the exit status, an integer. It is-9for a timeout, and127for a command that could not start. A command killed by signalnhas the status128 + ninrun()on Linux and macOS, as in a shell. Inrun_bin()andrun_pipeline(), the status is-n.stdout,stderr: the captured output, orNAwhen that stream was not captured.timeout:TRUEfor a timeout,FALSEotherwise.
The errors of run_pipeline() also carry result, the
condathis_pipeline result, and statuses, the status of each command.
Classes of each function
Each function also raises the shared classes above. The checks of
verbose, method and error raise only shared classes.
create_env()Arguments:
condathis_create_env_invalid_packages,condathis_create_env_positional_env_name,condathis_create_env_invalid_env_name,condathis_create_env_invalid_channels,condathis_create_env_invalid_channel_priority,condathis_create_env_invalid_platform,condathis_create_env_invalid_env_file,condathis_create_env_missing_env_file,condathis_create_env_invalid_overwriteandcondathis_create_env_conflicting_args(package specs andenv_file). The environment:condathis_create_env_exists(it exists, andoverwrite = FALSEcannot keep it) andcondathis_create_env_platform_mismatch. The backend:condathis_create_env_failed, and the warningcondathis_create_env_link_scripts_skipped.install_packages()Arguments:
condathis_install_packages_missing_packages,condathis_install_packages_invalid_packages,condathis_install_packages_positional_env_name,condathis_install_packages_invalid_env_name,condathis_install_packages_invalid_channelsandcondathis_install_packages_invalid_channel_priority. The environment:condathis_install_packages_env_not_found. The backend:condathis_install_packages_failed, and the warningcondathis_install_packages_link_scripts_skipped. The warningcondathis_install_packages_missing_previous_channelssays that a channel the environment was built from is not in the call. This holds on every backend that records the channels inconda-meta/history.remove_env()condathis_remove_env_invalid_env_name,condathis_remove_env_env_not_found,condathis_remove_env_failed, and the warningcondathis_remove_env_link_scripts_skipped(pre-unlink scripts).clean_cache()condathis_clean_cache_failed: a backend failed to clean its caches, orcondathiscould not empty one of its own cache directories. A backend failure also hascondathis_backend_error, with the error of the backend as the parent. For a non-zerostatusthat the backend returned without an error, it has the fieldsstatus,stdoutandstderrinstead. A directory failure has the error of the deletion as the parent.condathisraises it after it cleaned the other backends and directories. Astatusthat is not a whole number aborts withcondathis_backend_invalid_return. The warningscondathis_backend_not_installedandcondathis_backend_load_failedname a backend whose caches were not cleaned.validate_env()Arguments:
condathis_validate_env_invalid_packages,condathis_validate_env_positional_env_name,condathis_validate_env_invalid_env_name,condathis_validate_env_invalid_channelsandcondathis_validate_env_invalid_platform. The environment:condathis_validate_env_env_not_foundandcondathis_validate_env_unsatisfied. The backend:condathis_validate_env_failed.env_exists(),list_envs(),list_packages(),get_env_dir()andget_install_dir()condathis_<function>_invalid_env_namefor the functions that takeenv_name,condathis_list_packages_env_not_found, andcondathis_<function>_failed(not forget_env_dir()).install_micromamba()Arguments:
condathis_install_micromamba_invalid_micromamba_version,condathis_install_micromamba_invalid_timeout,condathis_install_micromamba_invalid_download_method,condathis_install_micromamba_invalid_forceandcondathis_install_micromamba_conflicting_args(timeoutandtimeout_limit). Thencondathis_install_micromamba_unsupported_versionandcondathis_install_micromamba_download_failed. The warningscondathis_install_micromamba_checksum_unavailableandcondathis_install_micromamba_checksum_mismatchconcern the SHA256 check of a download.- The micromamba backend
condathis_micromamba_status_error(amicromambacommand failed),condathis_micromamba_bin_path_not_executable,condathis_micromamba_version_not_detected, andcondathis_micromamba_not_available_for_arch.- Replacing an environment
For
create_env()withoverwrite = TRUE, on every backend, three classes apply.condathis_env_set_aside_failed: the existing environment could not be moved aside, so it is unchanged.condathis_env_not_restored: the create failed and the old environment could not be moved back. The error has the fieldkept_env_dirwith where it is kept. The warningcondathis_env_restore_failed: the same after an interrupt, also withkept_env_dir. The micromamba backend addscondathis_micromamba_env_set_aside_failedandcondathis_micromamba_env_restore_failed. Whencondathisreplaces, removes or cleans up an environment, it refuses to delete or move a directory that is not exactly<root>/envs/<env_name>. The error has the classcondathis_unsafe_env_dir_deleteorcondathis_unsafe_env_dir_move.run()andrun_bin()Arguments, with
runorrun_binas<function>:condathis_<function>_invalid_cmd,condathis_<function>_invalid_args(a value in..., alsocondathis_invalid_cmd_args),condathis_<function>_invalid_input,condathis_<function>_invalid_binary,condathis_<function>_invalid_env_nameandcondathis_<function>_invalid_<argument>fortimeout,supervise,cleanup_tree,linux_pdeathsig,stdin,stdout,stderrand, forrun_bin(),activate. Thencondathis_<function>_env_not_found,condathis_<function>_resolve_failed,condathis_<function>_status_errorandcondathis_<function>_timeout_error. A failed activation of the micromamba backend adds the classes of its error to the resolve error. On Linux and macOS, anactivate.dscript that exits with a non-zero status addscondathis_micromamba_status_errorandcondathis_cmd_status_error. A missing or unreadable activation result addscondathis_activation_dump_error, and a missing environment directory addscondathis_activation_env_not_found.run_pipeline()Arguments:
condathis_run_pipeline_invalid_step,condathis_run_pipeline_too_few_commands,condathis_run_pipeline_conflicting_method,condathis_run_pipeline_invalid_env_name,condathis_run_pipeline_invalid_input,condathis_run_pipeline_invalid_binaryandcondathis_run_pipeline_invalid_<argument>fortimeout,supervise,cleanup_tree,linux_pdeathsig,activate,stdin,stdoutandstderr. Thencondathis_run_pipeline_env_not_found,condathis_run_pipeline_resolve_failed,condathis_run_pipeline_status_errorandcondathis_run_pipeline_timeout_error.run_step()condathis_run_step_invalid_cmd,condathis_run_step_invalid_args,condathis_run_step_invalid_env_name,condathis_run_step_invalid_methodandcondathis_run_step_invalid_stderr.env_path()condathis_env_path_invalid_path(thepathargument),condathis_env_path_invalid(a malformedenv_path()object. It is also the second class of apatherror),condathis_env_path_read_only(passed to a function that takes only names),condathis_env_path_unsupported_method(amethodthat names a backend that cannot run commands in such an environment, alsocondathis_backend_unsupported), andcondathis_env_path_not_foundandcondathis_env_path_not_conda_env(alsocondathis_env_not_found).parse_output()condathis_parse_output_invalid_res,condathis_parse_output_invalid_stream,condathis_parse_output_invalid_trimandcondathis_parse_output_binary_stream(a raw stream cannot be parsed as text).with_sandbox_dir()The warning
condathis_with_sandbox_dir_cleanup_failed: the sandbox could not be deleted.- Backend selection (
method) condathis_backend_not_registered,condathis_backend_none_available,condathis_backend_mismatch(a change to an environment of another backend),condathis_backend_ambiguous_env(several backends have the environment),condathis_backend_not_installedandcondathis_backend_load_failed(the package of the backend cannot be used), and the warningscondathis_backend_mismatch_warning,condathis_backend_marker_mismatchandcondathis_invalid_backend_priority_option.register_backend()andunregister_backend()condathis_backend_invalid_name,condathis_backend_reserved_name,condathis_backend_root_conflict(the condathis data directory has an entry of that name that is not a directory),condathis_backend_name_conflict(the name differs only in case from another backend name),condathis_backend_class_conflictandcondathis_backend_contract_violation. A backend gives its own condition the classcondathis_backend_unsupportedwhen it cannot honor an argument, and never the classcondathis_backend_error.
Renamed classes
These classes of condathis 0.1.4 were renamed to follow the scheme.
Each old name is kept as an extra class until condathis 1.0, so
existing handlers keep working. Use the new names in new code.
| New class | Old class |
condathis_create_env_invalid_overwrite | condathis_create_invalid_overwrite_arg |
condathis_create_env_missing_env_file | condathis_create_missing_env_file |
condathis_remove_env_env_not_found | condathis_error_env_remove |
condathis_list_packages_env_not_found | condathis_list_packages_missing_env |
condathis_install_micromamba_download_failed | condathis_install_error_missing_bzip2 |
condathis_micromamba_bin_path_not_executable | condathis_umamba_bin_path_not_executable |
condathis_micromamba_version_not_detected | condathis_umamba_version_not_detected |
condathis_micromamba_not_available_for_arch | condathis_umamba_not_available_for_arch |
condathis_micromamba_status_error | condathis_cmd_status_error |
condathis_run_invalid_cmd | condathis_run_null_cmd |
condathis_run_invalid_stdin, condathis_run_bin_invalid_stdin | condathis_run_stdin_error |
condathis_run_bin_status_error | condathis_run_status_error |
condathis_run_invalid_args, condathis_run_bin_invalid_args (a named value) | rlib_error_dots_named, rlib_error_dots |
condathis_install_error_missing_bzip2 is deprecated: a failed download
does not depend on bzip2.
Examples
condathis::with_sandbox_dir({
# A missing environment, in any function
print(tryCatch(
condathis::list_packages(env_name = "no-such-env"),
condathis_env_not_found = function(cnd) "not found"
))
# An invalid argument aborts before anything runs
print(tryCatch(
condathis::create_env(env_name = "my-env", overwrite = "yes"),
condathis_invalid_arg = function(cnd) class(cnd)
))
})
#> [1] "not found"
#> [1] "condathis_create_env_invalid_overwrite"
#> [2] "condathis_create_invalid_overwrite_arg"
#> [3] "condathis_invalid_overwrite"
#> [4] "condathis_invalid_arg"
#> [5] "condathis_error"
#> [6] "rlang_error"
#> [7] "error"
#> [8] "condition"
if (FALSE) { # \dontrun{
condathis::with_sandbox_dir({
# The fields of a status error. The command is the Rscript of this R,
# run in the default environment, which is created empty.
rscript <- file.path(
R.home("bin"),
if (.Platform$OS.type == "windows") "Rscript.exe" else "Rscript"
)
tryCatch(
condathis::run(rscript, "-e", "quit(status = 3)", verbose = "silent"),
condathis_status_error = function(cnd) cnd$status
)
})
} # }