sammcj / gollama

Go manage your Ollama models
https://smcleod.net
MIT License
369 stars 26 forks source link

🐞 Bug: Fix index out of range error in quantColour function #78

Closed anrgct closed 1 month ago

anrgct commented 1 month ago

There's an index out of range error occurring in the quantColour function in styles.go. The error suggests that we're trying to access an index that is out of bounds for the synthGradient array.

Current behavior: The program panics with the following error:

runtime error: index out of range [15] with length 14

Expected behavior: The quantColour function should return a valid color without causing a panic.

Relevant code:

startLine: 50
endLine: 72

Problem analysis:

  1. The quantMap in the quantColour function has maximum index values of 15 (for "F32" and "FP32").
  2. The error message indicates that synthGradient only has a length of 14.
  3. This mismatch is causing an index out of range error when trying to access synthGradient[15].

Proposed solutions:

  1. Ensure that the synthGradient array has at least 16 elements (indices 0 to 15).
  2. Alternatively, modify quantMap so that its maximum index doesn't exceed the highest valid index of synthGradient.
  3. Add a safety check before returning:
    if index >= len(synthGradient) {
       index = len(synthGradient) - 1  // Use the last valid index
    }
    return lipgloss.Color(synthGradient[index])

Additional notes: