Skip to content

Conversation

Copy link

Copilot AI commented Jan 19, 2026

In vfox v1.0.0+, ctx.installedSdks changed from being indexed by version string to being indexed by SDK name. The PreUse hook was attempting ctx.installedSdks[input_version] which now returns nil, causing runtime errors.

Changes

  • hooks/pre_use.lua: Return ctx.version directly instead of looking it up in ctx.installedSdks

Before/After

# Before - fails with vfox v1.0.0+
local sdkInfo = ctx.installedSdks[input_version]  # nil lookup
local used_version = sdkInfo.version  # errors here

# After - compatible with all versions
return { version = ctx.version }

The Elixir plugin doesn't require version transformation logic, so direct passthrough is correct behavior per the vfox plugin interface.

Original prompt

This section details on the original issue you should resolve

<issue_title>PreUse hook fails due to assumption about ctx.installedSdks structure</issue_title>
<issue_description>### Description

While using the Elixir (and Erlang) plugin with vfox, I encountered a runtime error when executing vfox use. After some investigation, it appears that the plugin may be making an assumption about the structure of ctx.installedSdks that does not match its actual runtime shape.

I’d like to report my findings in case this is unintended behavior or could be improved.

Environment

  • OS: Windows 11

  • Shell: PowerShell

  • vfox version: (1.0.2)

  • Plugin: vfox-elixir / vfox-erlang.

Steps to Reproduce

  1. Install multiple versions of Elixir:
    -> v1.19.2-elixir-otp-28
    -> v1.19.2-elixir-otp-27
  2. Run: vfox use -g elixir
  3. Select a version when prompted.
plugin [preUse] error: err:C:\Users\cwl\.version-fox\plugin\elixir\hooks\pre_use.lua:15:        attempt to index a non-table object(nil) with key 'version'
stack traceback:
       C:\Users\cwl\.version-fox\plugin\elixir\hooks\pre_use.lua:15: in main chunk
       [G]: ?

Investigation / Observations

During debugging, I added some logging to inspect ctx.installedSdks inside PreUse. At runtime, it appears to have the following structure:

  ["elixir"] = {
    name = "elixir",
    version = "1.19.2-elixir-otp-27",
    path = "...",
  }
}

I added the following debug prints in PreUse:

function PLUGIN:PreUse(ctx)
    --- user input version
    local input_version = ctx.version
    print("input_version", input_version)
    print('---', ctx.installedSdks['elixir'].version)
    print('---', ctx.installedSdks['elixir'].path)
    print('---', ctx.installedSdks['elixir'].name)
    --- installed sdks
    local sdkInfo = ctx.installedSdks[input_version]
    print("sdkInfo", sdkInfo)
    local used_version = sdkInfo.version
    print("used_version", used_version)

    --- return the version information
    return {
        version = used_version
    }
end

the result is

PS C:\Users\xxx> vfox use -g elixir
Please select a version of elixir:
  -> 1.19.2-elixir-otp-28
input_version   1.19.2-elixir-otp-28
---     1.19.2-elixir-otp-27
---     C:\Users\xxx\.version-fox\cache\elixir\v-1.19.2-elixir-otp-27
---     elixir
sdkInfo nil
plugin [preUse] error: err:C:\Users\cwl\.version-fox\plugin\elixir\hooks\pre_use.lua:15: attempt to index a non-table object(nil) with key 'version'
stack traceback:
        C:\Users\cwl\.version-fox\plugin\elixir\hooks\pre_use.lua:15: in main chunk
        [G]: ?

This suggests that:

ctx.installedSdks is keyed by SDK name (e.g. "elixir"),

and contains only the currently selected SDK for that language.

However, the current PreUse implementation accesses it using the user-selected version string:

local sdkInfo = ctx.installedSdks[input_version]

When input_version is a full version string (e.g. 1.19.2-elixir-otp-28), this lookup returns nil, which then leads to the error.

Expected / Suggested Behavior

It seems that PreUse may not need to access ctx.installedSdks at all, and could simply return the resolved version string, similar to how the Node.js plugin handles PreUse.
For example:

function PLUGIN:PreUse(ctx)
    return {
        version = ctx.version
    }
end

Alternatively, if SDK metadata is required, it may need to be accessed via the SDK name (e.g. "elixir") rather than the version string.

Additional Notes

  • vfox list correctly shows all installed versions.

  • The issue appears to be limited to the plugin logic rather than vfox core behavior.

  • Node.js plugin does not exhibit this issue.

Closing

I’m not sure if this behavior is expected by design, but I wanted to share these observations in case it helps improve plugin compatibility with vfox’s context model.

Thank you for maintaining vfox and its plugins!</issue_description>

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

@yeshan333 It appears to be an incompatible change introduced after the vfox v1.0.0 version.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix PreUse hook error related to ctx.installedSdks structure Fix PreUse hook for vfox v1.0.0+ installedSdks structure change Jan 19, 2026
Copilot AI requested a review from bytemain January 19, 2026 12:47
@aooohan aooohan closed this Jan 19, 2026
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.

PreUse hook fails due to assumption about ctx.installedSdks structure

3 participants