Skip to content

Add BothToNull option for RunAndParse, and make ErrorNotice optional#2418

Merged
CLHatch merged 1 commit intomainfrom
RunAndLog
Jan 26, 2026
Merged

Add BothToNull option for RunAndParse, and make ErrorNotice optional#2418
CLHatch merged 1 commit intomainfrom
RunAndLog

Conversation

@CLHatch
Copy link
Contributor

@CLHatch CLHatch commented Jan 26, 2026

Pull request

Purpose
Describe the problem or feature in addition to a link to the issues.

Approach
How does this change address the problem?

Open Questions and Pre-Merge TODOs
Check all boxes as they are completed

  • Use github checklists. When solved, check the box and explain the answer.

Learning
Describe the research stage
Links to blog posts, patterns, libraries or addons used to solve this problem

Requirements
Check all boxes as they are completed

Summary by Sourcery

Add support for suppressing both stdout and stderr in RunAndLog and allow calls without an error notice handler.

Enhancements:

  • Extend RunAndLog to accept a combined BothToNull option for redirecting both stdout and stderr to /dev/null while preserving existing notice-based logging behavior.
  • Make the error notice type argument to RunAndLog optional so callers can choose not to emit error notices on failure.
  • Update update and template maintenance scripts and repo checks to use the new BothToNull option and explicit notice levels.

@CLHatch CLHatch requested a review from a team as a code owner January 26, 2026 02:41
@github-actions github-actions bot added the core Automatic label label Jan 26, 2026
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 26, 2026

Reviewer's Guide

Adds a new BothToNull option to RunAndLog/RunAndParse-style output handling, centralizes notice-type regex use, and makes the error notice type argument optional so callers can suppress error logging, then updates existing scripts to use the new options and calling convention.

Sequence diagram for RunAndLog with BothToNull and optional error notice

sequenceDiagram
    actor UserScript
    participant RunAndLog
    participant ShellCommand as Command
    participant Logger

    UserScript->>RunAndLog: RunAndLog "" BothToNull "" "" pushd SCRIPTPATH
    RunAndLog->>RunAndLog: Parse args and set
    RunAndLog->>RunAndLog: ErrToNull=true
    RunAndLog->>RunAndLog: OutToNull=true
    RunAndLog->>ShellCommand: Execute pushd SCRIPTPATH
    activate ShellCommand
    ShellCommand-->>RunAndLog: Non-zero exit code
    deactivate ShellCommand

    RunAndLog->>RunAndLog: Detect failure
    RunAndLog->>RunAndLog: Check ErrorNoticeType (empty)
    RunAndLog->>RunAndLog: Skip error logging
    RunAndLog-->>UserScript: Return failure code without logging

    Note over UserScript,RunAndLog: In check_repo and check_templates_repo
    UserScript->>RunAndLog: RunAndLog info git:info "" "" git -C path rev-parse
    RunAndLog->>ShellCommand: Execute git command
    ShellCommand-->>RunAndLog: Exit code
    RunAndLog-->>UserScript: Result with optional info logging
Loading

Class-style diagram for RunAndLog usage and new BothToNull option

classDiagram
    class RunAndLog {
        +RunAndLog(RunningNoticeType, OutputNoticeType, ErrorNoticeType, ErrorMessage, Command...)
        -NoticeTypes_Regex
        -Prefix
        -ErrToNull
        -OutToNull
        -OutputFile
    }

    class update_self {
        +update_self()
        -calls_RunAndLog_with_BothToNull()
    }

    class commands_update_self_logic {
        +commands_update_self_logic(Command, Notice)
        -calls_RunAndLog_with_BothToNull()
    }

    class update_templates {
        +update_templates()
        -calls_RunAndLog_with_BothToNull()
    }

    class commands_update_templates {
        +commands_update_templates(Command, Notice)
        -calls_RunAndLog_with_BothToNull()
    }

    class main_check_repo {
        +check_repo()
        -calls_RunAndLog_info_git_info_without_error_notice()
    }

    class main_check_templates_repo {
        +check_templates_repo()
        -calls_RunAndLog_info_git_info_without_error_notice()
    }

    RunAndLog <.. update_self : uses
    RunAndLog <.. commands_update_self_logic : uses
    RunAndLog <.. update_templates : uses
    RunAndLog <.. commands_update_templates : uses
    RunAndLog <.. main_check_repo : uses
    RunAndLog <.. main_check_templates_repo : uses

    class OutputNoticeOptions {
        +info
        +notice
        +warn
        +error
        +debug
        +trace
        +ErrToNull
        +OutToNull
        +BothToNull
    }

    RunAndLog --> OutputNoticeOptions : interprets

    class ErrorNoticeTypeOption {
        +fatal
        +warn
        +empty_allowed_to_suppress_logging
    }

    RunAndLog --> ErrorNoticeTypeOption : optional_argument
Loading

Flow diagram for updated RunAndLog output and error handling

flowchart TD
    A[RunAndLog called] --> B[Read parameters
RunningNoticeType
OutputNoticeType
ErrorNoticeType
ErrorMessage
Command]
    B --> C{OutputNoticeType
contains colon?}
    C -- yes --> C1[Set Prefix to
substring before colon]
    C -- no --> C2[Prefix is empty]

    C1 --> D[Build CommandText
Prefix command args]
    C2 --> D

    D --> E[Initialize
ErrToNull=false
OutToNull=false]

    E --> F{OutputNoticeType
matches errtonull
or bothtonull?}
    F -- yes --> F1[Set ErrToNull=true]
    F -- no --> G

    F1 --> G{OutputNoticeType
matches outtonull
or bothtonull?}
    E --> G
    G -- yes --> G1[Set OutToNull=true]
    G -- no --> H

    G1 --> H{ErrToNull != true
or OutToNull != true
and OutputNoticeType
matches NoticeTypes_Regex}
    F --> H
    H -- yes --> H1[Create OutputFile
with mktemp]
    H -- no --> I[No OutputFile]

    H1 --> I

    I --> J{ErrToNull == true
and OutToNull == true?}
    J -- yes --> J1[Run Command
stdout and stderr
redirected to /dev/null]
    J -- no --> K{ErrToNull == true
and OutputFile set?}

    K -- yes --> K1[Run Command
stdout -> OutputFile
stderr -> /dev/null]
    K -- no --> L{OutToNull == true
and OutputFile set?}

    L -- yes --> L1[Run Command
stderr -> OutputFile
stdout -> /dev/null]
    L -- no --> M{OutputFile set?}

    M -- yes --> M1[Run Command
stdout and stderr
-> OutputFile]
    M -- no --> M2[Run Command
stdout and stderr
unchanged]

    J1 --> N[Capture exit code
in result]
    K1 --> N
    L1 --> N
    M1 --> N
    M2 --> N

    N --> O{result == 0?}
    O -- yes --> P[Return success]
    O -- no --> Q{ErrorNoticeType
is non-empty?}

    Q -- yes --> Q1[Call ErrorNoticeType
with ErrorMessage and
Failing command text]
    Q -- no --> Q2[Skip error logging]

    Q1 --> R[Return failure code]
    Q2 --> R
Loading

File-Level Changes

Change Details Files
Extend RunAndLog to support combined stdout/stderr suppression and optional error notice logging.
  • Update RunAndLog documentation to clarify prefixed OutputNoticeType and how to skip optional arguments
  • Introduce a NoticeTypes_Regex variable for matching valid notice types
  • Add parsing for the new BothToNull OutputNoticeType to set both ErrToNull and OutToNull flags
  • Adjust the logic that decides when to create a temporary output file to avoid creating it when both streams go to /dev/null
  • Reorder conditional branches for running the command so they match the new ErrToNull/OutToNull handling and clarify comments about redirection targets
  • Wrap the error logging call in a conditional so ErrorNoticeType can be omitted to suppress error messages
.includes/misc_functions.sh
Update callers to use BothToNull and explicitly skip optional ErrorNoticeType when desired.
  • Change RunAndLog invocations in update_self and update_templates scripts from the "OutToNull
ErrToNull" pattern to the new BothToNull OutputNoticeType
  • Modify repository check helpers to call RunAndLog with info-level running/output notices and empty ErrorNoticeType/ErrorMessage arguments to avoid logging warnings on failure

  • Tips and commands

    Interacting with Sourcery

    • Trigger a new review: Comment @sourcery-ai review on the pull request.
    • Continue discussions: Reply directly to Sourcery's review comments.
    • Generate a GitHub issue from a review comment: Ask Sourcery to create an
      issue from a review comment by replying to it. You can also reply to a
      review comment with @sourcery-ai issue to create an issue from it.
    • Generate a pull request title: Write @sourcery-ai anywhere in the pull
      request title to generate a title at any time. You can also comment
      @sourcery-ai title on the pull request to (re-)generate the title at any time.
    • Generate a pull request summary: Write @sourcery-ai summary anywhere in
      the pull request body to generate a PR summary at any time exactly where you
      want it. You can also comment @sourcery-ai summary on the pull request to
      (re-)generate the summary at any time.
    • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
      request to (re-)generate the reviewer's guide at any time.
    • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
      pull request to resolve all Sourcery comments. Useful if you've already
      addressed all the comments and don't want to see them anymore.
    • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
      request to dismiss all existing Sourcery reviews. Especially useful if you
      want to start fresh with a new review - don't forget to comment
      @sourcery-ai review to trigger a new review!

    Customizing Your Experience

    Access your dashboard to:

    • Enable or disable review features such as the Sourcery-generated pull request
      summary, the reviewer's guide, and others.
    • Change the review language.
    • Add, remove or edit custom review instructions.
    • Adjust other review settings.

    Getting Help

    Copy link
    Contributor

    @sourcery-ai sourcery-ai bot left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Hey - I've left some high level feedback:

    • The errtonull|bothtonull checks are case-sensitive, so calls like RunAndLog "" BothToNull will not trigger the intended null redirection; either normalize OutputNoticeType to lowercase or update the regex to handle case-insensitive matching.
    • NoticeTypes_Regex is currently a global variable inside RunAndLog; consider declaring it local to avoid leaking it into the broader shell environment and accidentally impacting other code.
    Prompt for AI Agents
    Please address the comments from this code review:
    
    ## Overall Comments
    - The `errtonull|bothtonull` checks are case-sensitive, so calls like `RunAndLog "" BothToNull` will not trigger the intended null redirection; either normalize `OutputNoticeType` to lowercase or update the regex to handle case-insensitive matching.
    - `NoticeTypes_Regex` is currently a global variable inside `RunAndLog`; consider declaring it `local` to avoid leaking it into the broader shell environment and accidentally impacting other code.

    Sourcery is free for open source - if you like our reviews please consider sharing them ✨
    Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

    @CLHatch CLHatch merged commit 6c11a07 into main Jan 26, 2026
    16 checks passed
    @CLHatch CLHatch deleted the RunAndLog branch January 26, 2026 02:45
    @CLHatch
    Copy link
    Contributor Author

    CLHatch commented Jan 26, 2026

    @sourcery-ai resolve

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

    Labels

    core Automatic label

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    1 participant

    Comments