Skip to content

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

@dmarquez-splunk

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?

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