Skip to content

Unexpected output when using write_file() in starlark script #4222

@jemal

Description

@jemal

What version of Delve are you using (dlv version)?

1.25.2

What version of Go are you using? (go version)?

go version go1.25.4 linux/amd64

What operating system and processor architecture are you using?

Linux/NixOS - amd64

Description

Writing any output using write_file(...) inside a starlark script results in that output being quoted.

example.star:

def main():
    write_file("foo", "line1\nline2")
...
(dlv) source example.star
...

The contents of foo:

"line1\nline2"

Expected contents of foo:

line1
line2

This behavior prevents making functions like:

def command_save_breakpoints():
    buffer = ""
    bps = breakpoints().Breakpoints

    for bp in bps:
        if bp.ID <= 0:
            continue
        buffer += "b " + bp.File + ":" + str(bp.Line)
        if bp.Cond != "":
            buffer += " if " + bp.Cond
        buffer += "\n"

    if buffer != "":
        write_file(".breakpoints", buffer)
        print("Breakpoints saved to .breakpoints")

def command_load_breakpoints():
    dlv_command("source .breakpoints")

The issue is caused by the usage of the String() method on a starlark.Value.

// vendor/go.starlark.net/starlark/value.go
...
// Value is a value in the Starlark interpreter.
type Value interface {
	// String returns the string representation of the value.
	// Starlark string values are quoted as if by Python's repr.
	String() string
...
}
// pkg/terminal/starbind/starlark.go:128
err := os.WriteFile(string(path), []byte(args[1].String()), 0o640)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions