k6 icon indicating copy to clipboard operation
k6 copied to clipboard

output format for errors changes to structured log when running k6 as a subprocess

Open pablochacin opened this issue 9 months ago • 4 comments

Brief summary

When running k6 as a subprocess (from a go program) and capturing the stdout and stderr in a buffer, the format of error messages changes to a structured log format.

k6 version

v0.50.0

OS

windows

Docker version and image (if applicable)

No response

Steps to reproduce the problem

  1. Create an empty file named script.js

  2. Run the following go program:

package main

import (
	"bytes"
	"fmt"
	"os/exec"
)

func main() {

	cmd := exec.Command("k6", "run", "script.js")
	outBuff := bytes.NewBuffer(nil)
	cmd.Stdout = outBuff
	cmd.Stderr = outBuff

	cmd.Run()

	fmt.Println(outBuff.String())
}

Expected behaviour

The same output that is generated when running the script.js file with k6 in the console:

> k6 run script.js

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

ERRO[0000] could not initialize 'script.js': could not load JS test 'file:///home/pablo/go/src/github.com/grafana/grafana-api-tests/script.js': no exported functions in script 

Actual behaviour

The output has a structured log format:

> go run main.go 

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

time="2024-05-16T11:43:43+02:00" level=error msg="could not initialize 'script.js': could not load JS test 'file:///home/pablo/go/src/github.com/grafana/grafana-api-tests/script.js': no exported functions in script"

pablochacin avatar May 16 '24 09:05 pablochacin