Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 13, 2025

When external ulc.lua files contain syntax errors, server-side loading fails and MyVehicleConfig remains nil, causing cascading client-side errors when attempting to access its properties.

Changes

  • Client-side nil guards: Added defensive checks before accessing MyVehicleConfig properties in all 9 client modules (buttons, stages, brake, horn, park, cruise, signals, doors, reverse)
  • Contextual error messages: Added informative errors in helper functions that guide users to check server console for syntax error details
  • Verbose warning messages: Added warning logs to internal functions and event handlers that alert when they're called inappropriately without a valid configuration, helping diagnose when functions shouldn't be executing
  • Server-side diagnostics: Enhanced error output to explicitly label syntax errors with hints about common issues (missing commas, brackets, quotes)

Example

-- Before: crashes with "attempt to index a nil value"
function GetExtraByKey(key)
    for _, v in pairs(MyVehicleConfig.buttons) do
        if v.key == key then return v.extra end
    end
end

-- After: fails gracefully with actionable error
function GetExtraByKey(key)
    if not MyVehicleConfig then
        print("[ULC:GetExtraByKey] ERROR: MyVehicleConfig is not loaded. This usually means there's a syntax error in your ulc.lua file. Check server console for details.")
        return nil
    end
    for _, v in pairs(MyVehicleConfig.buttons) do
        if v.key == key then return v.extra end
    end
end

-- Internal functions also log warnings when called inappropriately
local function setBrakeExtras(newState)
    if not MyVehicleConfig then
        print("[ULC:setBrakeExtras] WARNING: Function called but MyVehicleConfig is not loaded. This function should not be called without a valid configuration.")
        return
    end
    -- function continues...
end

Script continues running when configs fail to load instead of producing repeated uncaught errors. Warning messages help identify when functions are being called in invalid states, making debugging easier.

Original prompt

This section details on the original issue you should resolve

<issue_title>Uncaught error</issue_title>
<issue_description>image

Probably just a syntax error in ulc.lua but it would be nice to catch it when config isn't loaded

Would be even better if there was a way to actually call the ulc.lua so it can tell us the problem somehow</issue_description>

<agent_instructions>Can you come up with an elegant way to catch these errors and add context to them?
MyVehicleConfig is usually not available due to syntax errors or similar issues. </agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits December 13, 2025 16:53
Co-authored-by: Flohhhhh <48927090+Flohhhhh@users.noreply.github.com>
Co-authored-by: Flohhhhh <48927090+Flohhhhh@users.noreply.github.com>
Co-authored-by: Flohhhhh <48927090+Flohhhhh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix uncaught error in ulc.lua configuration loading Add nil guards for MyVehicleConfig across client modules Dec 13, 2025
Copilot AI requested a review from Flohhhhh December 13, 2025 17:03
Copy link
Owner

@Flohhhhh Flohhhhh left a comment

Choose a reason for hiding this comment

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

Looks good, but let's be slightly more verbose overall, for example i think we really should never be calling a lot of these things at all when MyVehicleConfig is nil

It would be nice to log some sort of warning in case we try to do something we shouldn't.

…icleConfig

Co-authored-by: Flohhhhh <48927090+Flohhhhh@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 13, 2025

Looks good, but let's be slightly more verbose overall, for example i think we really should never be calling a lot of these things at all when MyVehicleConfig is nil

It would be nice to log some sor...

Added verbose warning messages to all internal functions and event handlers that shouldn't be called when MyVehicleConfig is nil. Now functions like setBrakeExtras, setCruiseLights, onDoorStateChange, setReverseExtras, and others will log clear warnings if they're inappropriately called without a valid configuration. (commit 1f53b15)

Co-authored-by: Flohhhhh <48927090+Flohhhhh@users.noreply.github.com>
Copilot AI changed the title Add nil guards for MyVehicleConfig across client modules Add nil guards and verbose warnings for MyVehicleConfig across client modules Dec 13, 2025
Copilot AI requested a review from Flohhhhh December 13, 2025 17:15
@Flohhhhh Flohhhhh marked this pull request as ready for review December 13, 2025 17:16
@Flohhhhh Flohhhhh changed the base branch from main to preview December 13, 2025 17:16
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.

Uncaught error

2 participants