Repository: syncthing/syncthing
File: cmd/syncthing/gui.go (Go)

Code before:
	if ok {
		for _, f := range panicFiles {
			panicF, _ := ioutil.ReadFile(f)
			arrayFile = addBufferFile(arrayFile, filepath.Base(f), panicF)
		}
	}

	versionPlatform, _ := json.MarshalIndent(map[string]string{
		"version":  Version,
		"codename": Codename,
		// "longVersion": LongVersion,
		"os":   runtime.GOOS,
		"arch": runtime.GOARCH,
	}, "", "  ")
	arrayFile = addBufferFile(arrayFile, "versionPlatform.json", versionPlatform)

	usageReportingData, _ := json.MarshalIndent(getusageReportingData(s, r), "", "  ")
	arrayFile = addBufferFile(arrayFile, "usageReportingData.json", usageReportingData)

	rawConf := s.cfg.RawCopy()
	debugCurrent := rawConf.GUI.Debugging
	if !debugCurrent {
		debugUndebug(s, rawConf, true)
	}

	heapPprof := getPprof(s, "/rest/debug/heapprof")
	filename := fmt.Sprintf("syncthing-heap-%s-%s-%s-%s.pprof", runtime.GOOS, runtime.GOARCH, Version, time.Now().Format("150405")) // hhmmss
	arrayFile = addBufferFile(arrayFile, filename, heapPprof)

	const duration = "4s"
	cpuPprof := getPprof(s, "/rest/debug/cpuprof?duration="+duration)
	filename = fmt.Sprintf("syncthing-cpu-%s-%s-%s-%s.pprof", runtime.GOOS, runtime.GOARCH, Version, time.Now().Format("150405")) // hhmmss
	arrayFile = addBufferFile(arrayFile, filename, cpuPprof)

	if !debugCurrent {
		debugUndebug(s, rawConf, false)
	}

	path := filepath.Join(baseDirs["config"], "support_bundle")
	os.MkdirAll(path, 0700)

	output := time.Now().Format("2006-01-02T15.04.05") + ".zip"
	newfilepath := filepath.Join(path, output)
	newfile, _ := os.Create(newfilepath)
	defer newfile.Close()

	zipBuffer(newfile, arrayFile)

	from, _ := os.Open(newfilepath)
	w.Header().Set("Content-Type", "application/zip")
	w.Header().Set("Content-Disposition", "attachment; filename="+output)

Review comment (bug):
I wouldn't grab these from the API. Instead, look at what the corresponding API methods do and just copy the code. It's just one to three lines each to create the profiles directly into a buffer, avoiding the API calls and undebug etc. stuff.

Code after:
	if jsonConfig, err := json.MarshalIndent(getRedactedConfig(s), "", "  "); err == nil {
		files = append(files, fileEntry{name: "config.json.txt", data: jsonConfig})
	} else {
		l.Warnln("Support bundle: failed to create config.json:", err)
	}

	// Log as a text
	var buflog bytes.Buffer
	for _, line := range s.systemLog.Since(time.Time{}) {
		fmt.Fprintf(&buflog, "%s: %s\n", line.When.Format(time.RFC3339), line.Message)
	}
	files = append(files, fileEntry{name: "log.txt", data: buflog.Bytes()})

	// Errors as a JSON
	if errs := s.guiErrors.Since(time.Time{}); len(errs) > 0 {
		if jsonError, err := json.MarshalIndent(errs, "", "  "); err != nil {
			files = append(files, fileEntry{name: "errors.json.txt", data: jsonError})
		} else {
			l.Warnln("Support bundle: failed to create errors.json:", err)
		}
	}

	// Panic files as a JSON
	if panicFiles, err := filepath.Glob(filepath.Join(baseDirs["config"], "panic*")); err == nil {
		for _, f := range panicFiles {
			if panicFile, err := ioutil.ReadFile(f); err != nil {
				l.Warnf("Support bundle: failed to load %s: %s", filepath.Base(f), err)
			} else {
				files = append(files, fileEntry{name: filepath.Base(f), data: panicFile})
			}
		}
	}

	// Version and platform information as a JSON
	if versionPlatform, err := json.MarshalIndent(map[string]string{
		"now":         time.Now().Format(time.RFC3339),
		"version":     Version,
		"codename":    Codename,
		"longVersion": LongVersion,
		"os":          runtime.GOOS,
		"arch":        runtime.GOARCH,
	}, "", "  "); err == nil {
		files = append(files, fileEntry{name: "version-platform.json.txt", data: versionPlatform})
	} else {
		l.Warnln("Failed to create versionPlatform.json: ", err)
	}

	// Report Data as a JSON
	if usageReportingData, err := json.MarshalIndent(reportData(s.cfg, s.model, s.connectionsService, usageReportVersion, true), "", "  "); err != nil {
		l.Warnln("Support bundle: failed to create versionPlatform.json:", err)
	} else {