Files
fn_registry/bash/functions/shell/bash_handle_error.md
T
egutierrez 61d8460149 feat: add bash shell utility functions
12 funciones Bash del dominio shell: utilidades de scripting (bash_log,
bash_colors, bash_check_deps, bash_confirm, bash_handle_error, bash_safe_run),
manipulacion de texto (convert_text_case), estructura de proyectos
(create_project_structure), y operaciones git (git_clean_branches,
git_log_visual, git_push_all_remotes, git_repo_status). Cada una con su
.sh y .md de frontmatter.
2026-04-12 13:54:15 +02:00

2.1 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path, source_repo, source_license, source_file
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports params output tested tests test_file_path file_path source_repo source_license source_file
bash_handle_error function bash shell 1.0.0 impure handle_error(error_code: string, error_description: string, [solution: string]) -> exit_code Muestra un box de error formateado con contexto del fallo: script, linea, funcion, directorio y usuario. Registra en log.
bash
error
handler
box
formatted
context
bash_colors_bash_shell
bash_log_bash_shell
false error_go_core
name desc
error_code codigo identificador del error, ej: BUILD_FAILED, DB_CONNECTION_ERROR
name desc
error_description descripcion legible del error para mostrar al usuario
name desc
solution solucion sugerida; opcional; si se provee se muestra en seccion separada
box de error formateado en stdout con contexto (script, linea, funcion, directorio, usuario) + registro en log; retorna exit code 1 false
bash/functions/shell/bash_handle_error.sh https://gitea-dgg044oo04woo4ggcsws4gk0.organic-machine.com/egutierrez/DevLauncher.git MIT scripts/lib/common.sh

Ejemplo

source bash/functions/shell/bash_handle_error.sh

build_project() {
    go build ./... || handle_error "BUILD_FAILED" \
        "La compilacion del proyecto fallo" \
        "Ejecuta 'go mod tidy' y verifica que todas las dependencias esten instaladas"
}

connect_db() {
    psql "$DB_URL" -c '\q' 2>/dev/null || handle_error "DB_CONNECTION_ERROR" \
        "No se pudo conectar a la base de datos"
}

Notas

El box usa caracteres unicode de bash_colors (BOX_TL, BOX_H, etc.) para el borde en rojo. La informacion de contexto se extrae de BASH_SOURCE, BASH_LINENO y FUNCNAME con offset 2 para apuntar al caller del caller.

La funcion siempre retorna 1, permitiendo usarla como cmd || handle_error ... en pipelines de error.

Usa bash_colors y bash_log como dependencias. Sourcea ambas automaticamente al cargarse.