diff --git a/clients/broadcaster_local.go b/clients/broadcaster_local.go index 9d96de56a..7b7f78129 100644 --- a/clients/broadcaster_local.go +++ b/clients/broadcaster_local.go @@ -5,6 +5,8 @@ import ( "fmt" "io" "net/url" + + "github.com/livepeer/catalyst-api/log" ) // Currently only implemented by LocalBroadcasterClient @@ -20,7 +22,7 @@ type LocalBroadcasterClient struct { func NewLocalBroadcasterClient(broadcasterURL string) (BroadcasterClient, error) { u, err := url.Parse(broadcasterURL) if err != nil { - return &LocalBroadcasterClient{}, fmt.Errorf("error parsing local broadcaster URL %q: %s", broadcasterURL, err) + return &LocalBroadcasterClient{}, fmt.Errorf("error parsing local broadcaster URL %q: %s", log.RedactURL(broadcasterURL), err) } return &LocalBroadcasterClient{ broadcasterURL: *u, diff --git a/clients/callback_client.go b/clients/callback_client.go index 28f7f52f7..eaa7a3231 100644 --- a/clients/callback_client.go +++ b/clients/callback_client.go @@ -176,12 +176,12 @@ func (pcc *PeriodicCallbackClient) doWithRetries(r *http.Request) error { resp, err := metrics.MonitorRequest(metrics.Metrics.TranscodingStatusUpdate, pcc.httpClient, r) if err != nil { - return fmt.Errorf("failed to send callback to %q. Error: %s", r.URL.String(), err) + return fmt.Errorf("failed to send callback to %q. Error: %s", r.URL.Redacted(), err) } defer resp.Body.Close() if resp.StatusCode >= 400 { - return fmt.Errorf("failed to send callback to %q. HTTP Code: %d", r.URL.String(), resp.StatusCode) + return fmt.Errorf("failed to send callback to %q. HTTP Code: %d", r.URL.Redacted(), resp.StatusCode) } return nil diff --git a/errors/errors.go b/errors/errors.go index 55164d546..62b2a992a 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -5,11 +5,9 @@ import ( "errors" "fmt" "net/http" - "strings" "github.com/cenkalti/backoff/v4" "github.com/livepeer/catalyst-api/log" - "github.com/xeipuuv/gojsonschema" ) type APIError struct { @@ -23,7 +21,12 @@ func writeHttpError(w http.ResponseWriter, msg string, status int, err error) AP var errorDetail string if err != nil { - errorDetail = err.Error() + switch status { + case http.StatusInternalServerError: + log.LogNoRequestID("returning HTTP 500", "http_error_msg", msg, "err", err) + default: + errorDetail = err.Error() + } } if err := json.NewEncoder(w).Encode(map[string]string{"error": msg, "error_detail": errorDetail}); err != nil { @@ -53,18 +56,6 @@ func WriteHTTPInternalServerError(w http.ResponseWriter, msg string, err error) return writeHttpError(w, msg, http.StatusInternalServerError, err) } -func WriteHTTPBadBodySchema(where string, w http.ResponseWriter, errors []gojsonschema.ResultError) APIError { - sb := strings.Builder{} - sb.WriteString("Body validation error in ") - sb.WriteString(where) - sb.WriteString(" ") - for i := 0; i < len(errors); i++ { - sb.WriteString(errors[i].String()) - sb.WriteString(" ") - } - return writeHttpError(w, sb.String(), http.StatusBadRequest, nil) -} - type unretriableError struct{ error } // Unretriable returns an error that should be treated as final. This effectively means that the error stops backoff diff --git a/pipeline/coordinator.go b/pipeline/coordinator.go index 3f625732d..12bb9932e 100644 --- a/pipeline/coordinator.go +++ b/pipeline/coordinator.go @@ -303,7 +303,7 @@ func (c *Coordinator) StartUploadJob(p UploadJobPayload) { // Use new clipped manifest as the source URL clipSourceURL, err := clients.ClipInputManifest(p.RequestID, sourceURL.String(), p.ClipTargetURL.String(), p.ClipStrategy.StartTime, p.ClipStrategy.EndTime) if err != nil { - return fmt.Errorf("clipping failed: %s %w", sourceURL, err) + return fmt.Errorf("clipping failed: %s %w", sourceURL.Redacted(), err) } sourceURL = clipSourceURL return nil diff --git a/pipeline/ffmpeg.go b/pipeline/ffmpeg.go index a0b8bf64d..56952b0a4 100644 --- a/pipeline/ffmpeg.go +++ b/pipeline/ffmpeg.go @@ -311,7 +311,7 @@ func (f *ffmpeg) probeSourceSegment(requestID string, seg *m3u8.MediaSegment, so } probeURL, err := clients.SignURL(u) if err != nil { - return fmt.Errorf("failed to create signed url for %s: %w", u, err) + return fmt.Errorf("failed to create signed url for %s: %w", u.Redacted(), err) } if err := backoff.Retry(func() error { _, err = f.probe.ProbeFile(requestID, probeURL) @@ -350,7 +350,7 @@ func copyFileToLocalTmpAndSegment(job *JobInfo) (string, error) { defer cancel() _, err = clients.CopyFile(timeout, job.SignedSourceURL, localSourceFile.Name(), "", job.RequestID) if err != nil { - return fmt.Errorf("failed to copy file (%s) locally for segmenting: %s", job.SignedSourceURL, err) + return fmt.Errorf("failed to copy file (%s) locally for segmenting: %s", log.RedactURL(job.SignedSourceURL), err) } return nil }, retries(6)); err != nil { diff --git a/transcode/transcode.go b/transcode/transcode.go index 621e49b18..c16a1fa3a 100644 --- a/transcode/transcode.go +++ b/transcode/transcode.go @@ -113,7 +113,7 @@ func RunTranscodeProcess(transcodeRequest TranscodeSegmentRequest, streamName st lastSegment := sourceSegmentURLs[len(sourceSegmentURLs)-1] lastSegmentURL, err := clients.SignURL(lastSegment.URL) if err != nil { - return outputs, segmentsCount, fmt.Errorf("failed to create signed url for last segment %s: %w", lastSegment.URL, err) + return outputs, segmentsCount, fmt.Errorf("failed to create signed url for last segment %s: %w", lastSegment.URL.Redacted(), err) } // ignore the following probe errors when checking the last segment var ignoreProbeErrs = []string{ @@ -397,13 +397,13 @@ func RunTranscodeProcess(transcodeRequest TranscodeSegmentRequest, streamName st var err error probeURL, err = clients.SignURL(mp4TargetUrl) if err != nil { - return outputs, segmentsCount, fmt.Errorf("failed to create signed url for %s: %w", mp4TargetUrl, err) + return outputs, segmentsCount, fmt.Errorf("failed to create signed url for %s: %w", mp4TargetUrl.Redacted(), err) } } // Populate OutputVideo structs with results from probing step to send back in final response to Studio mp4Out, err = video.PopulateOutput(transcodeRequest.RequestID, video.Probe{}, probeURL, mp4Out) if err != nil { - return outputs, segmentsCount, fmt.Errorf("failed to populate output for %s: %w", probeURL, err) + return outputs, segmentsCount, fmt.Errorf("failed to populate output for %s: %w", log.RedactURL(probeURL), err) } mp4Outputs = append(mp4Outputs, mp4Out) } @@ -657,7 +657,7 @@ func processTranscodeResult( targetRenditionURL, err := url.JoinPath(targetOSURL.String(), profile.Name) if err != nil { - return fmt.Errorf("error building rendition segment URL %q: %s", targetRenditionURL, err) + return fmt.Errorf("error building rendition segment URL %q: %s", log.RedactURL(targetRenditionURL), err) } if transcodeRequest.GenerateMP4 {