diff --git a/error.go b/error.go index 7ac25d28..4302606e 100644 --- a/error.go +++ b/error.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "net/http" + "os" ) // ErrorDetailer returns error details for responses & debugging. This enables @@ -264,7 +265,7 @@ func WriteErr(api API, ctx Context, status int, msg string, errs ...error) error writeErr := writeResponse(api, ctx, status, "", err) if writeErr != nil { // If we can't write the error, log it so we know what happened. - fmt.Printf("could not write error: %s\n", writeErr) + fmt.Fprintf(os.Stderr, "could not write error: %v\n", writeErr) } return writeErr } diff --git a/humacli/humacli.go b/humacli/humacli.go index 9db7f8a4..5942a729 100644 --- a/humacli/humacli.go +++ b/humacli/humacli.go @@ -165,7 +165,7 @@ func (c *cli[O]) setupOptions(t reflect.Type, path []int) { if !field.IsExported() { // This isn't a public field, so we cannot use reflect.Value.Set with // it. This is usually a struct field with a lowercase name. - fmt.Println("warning: ignoring unexported options field", field.Name) + fmt.Fprintln(os.Stderr, "warning: ignoring unexported options field", field.Name) continue } @@ -298,7 +298,7 @@ func New[O any](onParsed func(Hooks, *O)) CLI { // Server is done, just exit. case <-quit: if c.stop != nil { - fmt.Println("Gracefully shutting down the server...") + fmt.Fprintln(os.Stderr, "Gracefully shutting down the server...") c.stop() } } diff --git a/sse/sse.go b/sse/sse.go index edda12c5..0d648c23 100644 --- a/sse/sse.go +++ b/sse/sse.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "net/http" + "os" "reflect" "runtime/debug" "time" @@ -160,10 +161,10 @@ func Register[I any](api huma.API, op huma.Operation, eventTypeMap map[string]an send := func(msg Message) error { if deadliner != nil { if err := deadliner.SetWriteDeadline(time.Now().Add(WriteTimeout)); err != nil { - fmt.Println("warning: unable to set write deadline: " + err.Error()) + fmt.Fprintf(os.Stderr, "warning: unable to set write deadline: %v\n", err) } } else { - fmt.Println("warning: unable to set write deadline") + fmt.Fprintln(os.Stderr, "write deadline not supported by underlying writer") } // Write optional fields @@ -176,7 +177,7 @@ func Register[I any](api huma.API, op huma.Operation, eventTypeMap map[string]an event, ok := typeToEvent[deref(reflect.TypeOf(msg.Data))] if !ok { - fmt.Println("error: unknown event type", reflect.TypeOf(msg.Data)) + fmt.Fprintf(os.Stderr, "error: unknown event type %v\n", reflect.TypeOf(msg.Data)) debug.PrintStack() } if event != "" && event != "message" { @@ -198,7 +199,7 @@ func Register[I any](api huma.API, op huma.Operation, eventTypeMap map[string]an if flusher != nil { flusher.Flush() } else { - fmt.Println("error: unable to flush") + fmt.Fprintln(os.Stderr, "error: unable to flush") return fmt.Errorf("unable to flush: %w", http.ErrNotSupported) } return nil diff --git a/transforms.go b/transforms.go index 9c5a0db2..2dd0e037 100644 --- a/transforms.go +++ b/transforms.go @@ -3,6 +3,7 @@ package huma import ( "bytes" "fmt" + "os" "path" "reflect" ) @@ -132,7 +133,7 @@ func (t *SchemaLinkTransformer) OnAddOperation(oapi *OpenAPI, op *Operation) { // Catch some scenarios that just aren't supported in Go at the // moment. Logs an error so people know what's going on. // https://github.com/danielgtaylor/huma/issues/371 - fmt.Println("Warning: unable to create schema link for type", typ, ":", r) + fmt.Fprintln(os.Stderr, "Warning: unable to create schema link for type", typ, ":", r) } }() newType := reflect.StructOf(fields)