Skip to content

Improve logging and error handling#1358

Merged
aknysh merged 60 commits intomainfrom
improve-error-handling
Jul 1, 2025
Merged

Improve logging and error handling#1358
aknysh merged 60 commits intomainfrom
improve-error-handling

Conversation

@aknysh
Copy link
Member

@aknysh aknysh commented Jun 28, 2025

what

  • Improve logging

    • Remove the deprecated logs functions throughout the codebase
    • Only use the structured log functions (log.Info, log.Debug, log.Warn)
  • Improve error handling

    • Add a new Go package errors with all functions and data structures related to error handling in the codebase (all other packages import the errors package and call its functions)
    • Remove all functions from the codebase that would exit the program execution earlier: panic(), log.Fatal(), os.Exit(), and some old Atmos error handling functions
    • In the new errors package, add a function to print errors in Markdown format (if Markdown is configured and TTY is supported), and a function to print errors and exit the program execution
  • Don't process Atmos YAML functions and Go templates in atmos validate stacks

why

  • Improve logging

    • Standardize logs
    • Make it easy to parse and analyze by log aggregators, SIEM tools, or monitoring systems
    • Easier integration with tracing/Telemetry
    • Consistency across logs
    • Better debugging and contextual info
    • Improved querying and filtering
  • Improve error handling

    • Better, standard UI/UX
    • All errors and program exits are handled in just one place, allowing easily configuring the look and feel of all error messages, and adding hooks for Tracing/Telemetry with just a few lines of code/config
    • All early exits from any functions in the codebase (due to errors or other conditions) are now funneled through just one function in the errors package, allowing easier controlling the code execution and exit behavior
  • Don't process Atmos YAML functions and Go templates in atmos validate stacks. YAML functions and Go templates can access backends and clouds, but atmos validate stacks should not require authentication and assuming roles

test

atmos terraform apply --affected --all --dry-run

image

atmos terraform apply component-1 -s nonprods

image

atmos terraform apply component-2 -s prod

image

atmos terraform apply component-1 -s nonprod

image

atmos terraform apply --all --logs-level=Debu

image

Summary by CodeRabbit

  • Refactor

    • Unified and centralized error handling and logging throughout the application, replacing various custom and utility functions with a single standardized error handling mechanism and structured logging.
    • Deprecated and removed old logging and error-printing functions, streamlining output and error reporting.
    • Updated error messages and output formatting for improved clarity and consistency.
    • Reduced redundant debug output for a cleaner user experience.
  • Bug Fixes

    • Improved error reporting for invalid log levels and plan file differences with clearer, Markdown-formatted messages.
  • Tests

    • Updated and added tests to validate new error handling and output formats.
    • Removed obsolete tests for deprecated logging and error functions.
  • Chores

    • Updated dependency google.golang.org/api to v0.239.0.
    • Reorganized and cleaned up import statements across multiple files.
    • Enhanced configuration and test comments for clarity and consistency.
  • Documentation

    • Improved in-code comments and documentation for better maintainability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor New features that do not break anything size/xl Extra large size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants