Skip to content

Compatibility issues with sprig dig function between 1.16 and 1.17 #875

Description

@dmarquez-splunk

Hello!

Very new to this repo so looking for some advice on what may be causing the issues I am about to describe.

I have a sample go program as follows:

package main

import (
	"fmt"

	"github.com/Masterminds/sprig/v3"
	"github.com/expr-lang/expr"
)

func main() {
	// Example map to test dig
	labels := map[string]any{
		"some": map[string]any{
			"label": map[string]any{
				"io/creator-email": "test@example.com",
			},
		},
	}

	// Build environment with dig
	env := map[string]any{
		"sprig":  sprig.GenericFuncMap(),
		"labels": labels,
	}

	// Compile expression
	program, err := expr.Compile("sprig.dig('some', 'label', 'io/creator-email', nil, labels)", expr.Env(env))
	if err != nil {
		fmt.Println("Compile error:", err)
		return
	}

	// Run expression
	output, err := expr.Run(program, env)
	if err != nil {
		fmt.Println("Runtime error:", err)
		return
	}

	fmt.Println("Result:", output)
}

When using this program with expr-lang 1.16.9 I get:
Result: test@example.com

However, when upgrading to 1.17.X (while keeping sprig module the same) I get:

Runtime error: runtime error: index out of range [3] with length 1 (1:7)
 | sprig.dig('some', 'label', 'io/creator-email', nil, labels)
 | ......^

Any thought what may be causing this?

Activity

  1. changed the title [-]Compatibility issues with sprig functions between 1.16 and 1.17[/-] [+]Compatibility issues with sprig dig function between 1.16 and 1.17[/+] on Dec 9, 2025
  2. thevilledev commented on Dec 10, 2025

    @thevilledev
    Contributor

    Hey!

    I wrote a small test case to try and reproduce this:

    func TestSprigDigCompatibility(t *testing.T) {
            // Simulating sprig.GenericFuncMap() - a map containing functions
            funcMap := map[string]any{
                    "dig": func(ps ...any) (any, error) {
                            // Simplified dig implementation - just return the default value
                            if len(ps) < 2 {
                                    return nil, nil
                            }
                            return ps[len(ps)-2], nil
                    },
            }
    
            labels := map[string]any{
                    "some": map[string]any{
                            "label": map[string]any{
                                    "io/creator-email": "test@example.com",
                            },
                    },
            }
    
            env := map[string]any{
                    "sprig":  funcMap,
                    "labels": labels,
            }
    
            program, err := expr.Compile("sprig.dig('some', 'label', 'io/creator-email', nil, labels)", expr.Env(env))
            require.NoError(t, err)
    
            output, err := expr.Run(program, env)
            require.NoError(t, err)
            require.Nil(t, output) // Our simplified dig returns the default (nil)
    
            // Print disassembly for debugging
            fmt.Println("Disassembly:")
            fmt.Println(program.Disassemble())
    }

    Runs fine on v1.16.9, but fails on all tagged releases after to the same error you're seeing:

    runtime error: index out of range [3] with length 1 (1:7)
    

    But the good thing is that it runs fine on master. I believe I fixed this in #868. It will be part of the next release, presumably v1.17.7.

  3. antonmedv commented on Dec 10, 2025

    @antonmedv
    Member

    Yes! I will release v1.17.7 very soon 🙌

  4. locked and limited conversation to collaborators on Dec 10, 2025
  5. converted this issue into a discussion #877 on Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions