in main/cmds.go [157:196]
func enable(ctx *log.Context, h HandlerEnvironment, seqNum int) (string, error) {
// parse the extension handler settings (not available prior to 'enable')
cfg, err := parseAndValidateSettings(ctx, h.HandlerEnvironment.ConfigFolder, seqNum)
if err != nil {
return "", errors.Wrap(err, "failed to get configuration")
}
dir := filepath.Join(dataDir, downloadDir, fmt.Sprintf("%d", seqNum))
if err := downloadFiles(ctx, dir, cfg); err != nil {
return "", errors.Wrap(err, "processing file downloads failed")
}
// execute the command, save its error
runErr := runCmd(ctx, dir, cfg)
// collect the logs if available
stdoutF, stderrF := logPaths(dir)
stdoutTail, err := tailFile(stdoutF, maxTailLen)
if err != nil {
ctx.Log("message", "error tailing stdout logs", "error", err)
}
stderrTail, err := tailFile(stderrF, maxTailLen)
if err != nil {
ctx.Log("message", "error tailing stderr logs", "error", err)
}
isSuccess := runErr == nil
telemetry("Output", "-- stdout/stderr omitted from telemetry pipeline --", isSuccess, 0)
if isSuccess {
ctx.Log("event", "enabled")
} else {
ctx.Log("event", "enable script failed")
}
msg := fmt.Sprintf("\n[stdout]\n%s\n[stderr]\n%s", string(stdoutTail), string(stderrTail))
// Always report nil for error because extension should not fail if script throws error
// Error still will be reported in the message
return msg, nil
}