Skip to content

Conversation

@MacFlorent
Copy link
Contributor

@MacFlorent MacFlorent commented Jan 20, 2026

Fix for issue #302

Summary by Sourcery

Fix nearest airbase lookup and ATIS generation when airbases are missing or no longer exist.

Bug Fixes:

  • Guard against non-existent or invalid airbases when building the nearest airbase list to avoid runtime errors.
  • Prevent ATIS creation and access for invalid or non-existent airbases, returning a fallback message instead of failing.

Enhancements:

  • Add logging to trace failed ATIS creation attempts for specific airbases.
  • Bump veafAirbases and veafWeather module version numbers to reflect the changes.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 20, 2026

Reviewer's Guide

Updates airbase and weather modules to safely handle missing or non-existent DCS airbases when computing nearest airbases and generating ATIS, and bumps their version numbers.

Sequence diagram for updated getNearestAirbaseList handling invalid airbases

sequenceDiagram
    participant Caller
    participant veafAirbases
    participant veafAirbase
    participant DcsAirbase
    participant dcsUnit
    participant mist_utils as mist_utils

    Caller->>veafAirbases: getNearestAirbaseList(dcsUnit, iCount)
    activate veafAirbases
    veafAirbases->>dcsUnit: getPoint()
    dcsUnit-->>veafAirbases: vec3Unit

    loop for each veafAirbase in Airbases
        veafAirbases->>veafAirbase: access DcsAirbase
        alt veafAirbase and DcsAirbase exist and DcsAirbase:isExist()
            veafAirbases->>DcsAirbase: getPoint()
            DcsAirbase-->>veafAirbases: vec3Airbase
            veafAirbases->>mist_utils: get2DDist(vec3Unit, vec3Airbase)
            mist_utils-->>veafAirbases: iDistance

            veafAirbases->>veafAirbases: try fill first nil slot in nearestList
            alt nearestList slot found
                veafAirbases->>veafAirbases: insert {veafAirbase, iDistance}
            else no nil slot
                veafAirbases->>veafAirbases: compare with farthest entry
                alt iDistance is shorter
                    veafAirbases->>veafAirbases: replace farthest entry
                else
                    veafAirbases->>veafAirbases: ignore current airbase
                end
            end

            alt airbase was added or replaced
                veafAirbases->>veafAirbases: table.sort(nearestList, Sort)
            end
        else invalid or non existent DcsAirbase
            veafAirbases->>veafAirbases: skip this veafAirbase
        end
    end

    veafAirbases-->>Caller: nearestList
    deactivate veafAirbases
Loading

Updated class diagram for veafAirbases and veafWeatherAtis error handling

classDiagram
    class veafAirbases {
        +string Id
        +string Version
        +table Airbases
        +getNearestAirbaseList(dcsUnit, iCount) nearestList
    }

    class VeafAirbase {
        +string Name
        +DcsAirbase DcsAirbase
    }

    class DcsAirbase {
        +getPoint() vec3
        +isExist() bool
    }

    class mist_utils {
        +get2DDist(vec3Unit, vec3Airbase) number
    }

    class veafWeatherAtis {
        +table ListInEffect
        +Create(veafAirbase, dateTimeZulu) veafWeatherAtis
        +getAtis(veafAirbase) veafWeatherAtis
        +getAtisString(veafAirbase) string
    }

    class veafLogger {
        +trace(message) void
    }

    veafAirbases "*" --> "*" VeafAirbase : manages
    VeafAirbase --> DcsAirbase : wraps
    veafAirbases --> mist_utils : uses

    veafWeatherAtis --> VeafAirbase : uses
    veafWeatherAtis --> veafLogger : logs
    veafWeatherAtis --> DcsAirbase : checksExistence
Loading

File-Level Changes

Change Details Files
Harden nearest-airbase computation against nil or non-existent DCS airbases.
  • Wrap per-airbase processing in a guard that checks veafAirbase, its DcsAirbase field, and DcsAirbase:isExist() before accessing the point.
  • Only compute distance and manipulate the nearestList when the airbase passes validity checks.
  • Keep the nearest-list filling and replacement logic the same but scoped inside the new existence check, including conditional sorting only when an entry was added.
src/scripts/veaf/veafAirbases.lua
Harden ATIS creation and retrieval against invalid airbases and expose clearer logging and messaging when ATIS cannot be created.
  • Add early-return guard in veafWeatherAtis:Create to return nil when the provided veafAirbase or its DcsAirbase is nil or non-existent.
  • Update veafWeatherAtis.getAtis to log a failure message when ATIS creation returns nil, and only log the "New ATIS" trace when creation succeeds.
  • Update veafWeatherAtis.getAtisString to handle nil ATIS objects by returning a user-facing message indicating no ATIS is available for the airbase instead of indexing a nil value.
src/scripts/veaf/veafWeather.lua

Possibly linked issues


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

@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:

  • In veafWeatherAtis.getAtis/getAtisString, consider validating veafAirbase before using veafAirbase.Name so a nil airbase (which Create now explicitly supports) does not cause a runtime error when logging or building the fallback string.
  • In veafAirbases.getNearestAirbaseList, you still sort nearestList on every successful insertion; if performance becomes an issue with many airbases, you could defer sorting until after the loop or use a more incremental approach to maintain the ordered list.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `veafWeatherAtis.getAtis`/`getAtisString`, consider validating `veafAirbase` before using `veafAirbase.Name` so a nil airbase (which `Create` now explicitly supports) does not cause a runtime error when logging or building the fallback string.
- In `veafAirbases.getNearestAirbaseList`, you still sort `nearestList` on every successful insertion; if performance becomes an issue with many airbases, you could defer sorting until after the loop or use a more incremental approach to maintain the ordered list.

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getNearestAirbaseList throws "Object doesn't exist" error with destroyed/stale airbase references

2 participants