Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pkg/terminal/starbind/starlark.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,17 @@ func New(ctx Context, out EchoWriter) *Env {
if !ok {
return nil, decorateError(thread, errors.New("first argument of write_file was not a string"))
}
err := os.WriteFile(string(path), []byte(args[1].String()), 0o640)
var data []byte
switch v := args[1].(type) {
case starlark.String:
data = []byte(string(v))
case starlark.Bytes:
data = []byte(v)
default:
err := fmt.Errorf("second argument of write_file must be a string or bytes, got %s", args[1].Type())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the default should still be to call String.

return starlark.None, decorateError(thread, err)
}
err := os.WriteFile(string(path), data, 0o640)
return starlark.None, decorateError(thread, err)
})
builtindoc(writeFileBuiltinName, "(Path, Text)", "writes text to the specified file.")
Expand Down