Repository: goadesign/goa
Pull request #3545 (2024-07-03 05:12:57)

Fix misc issues with server example generation


Patch:
diff --git a/codegen/example/templates/server_handler.go.tpl b/codegen/example/templates/server_handler.go.tpl
index 6870eedb..82a84121 100644
--- a/codegen/example/templates/server_handler.go.tpl
+++ b/codegen/example/templates/server_handler.go.tpl
@@ -20,14 +20,14 @@
 						}
 					}
 					if !{{ .VarName }}Seen {
-						log.Fatalf(ctx, "invalid value for URL '{{ .Name }}' variable: %q (valid values: {{ join .Values "," }})\n", *{{ .VarName }}F)
+						log.Fatal(ctx, fmt.Errorf("invalid value for URL '{{ .Name }}' variable: %q (valid values: {{ join .Values "," }})\n", *{{ .VarName }}F))
 					}
 				{{- end }}
 				addr = strings.Replace(addr, "{{ printf "{%s}" .Name }}", *{{ .VarName }}F, -1)
 			{{- end }}
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "{{ $u.Transport.Type }}s"
@@ -38,7 +38,7 @@
 			if *{{ $u.Transport.Type }}PortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *{{ $u.Transport.Type }}PortF)
 			} else if u.Port() == "" {
@@ -50,5 +50,5 @@
 	{{ end }}
 {{- end }}
 	default:
-		log.Fatalf(ctx, "invalid host argument: %q (valid hosts: {{ join .Server.AvailableHosts "|" }})\n", *hostF)
+		log.Fatal(ctx, fmt.Errorf("invalid host argument: %q (valid hosts: {{ join .Server.AvailableHosts "|" }})\n", *hostF))
 	}	
\ No newline at end of file


Test patch:
diff --git a/codegen/example/testdata/server-no-server.golden b/codegen/example/testdata/server-no-server.golden
index 203682e1..097881aa 100644
--- a/codegen/example/testdata/server-no-server.golden
+++ b/codegen/example/testdata/server-no-server.golden
@@ -64,7 +64,7 @@ func main() {
 			addr := "http://localhost:80"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -75,7 +75,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -88,7 +88,7 @@ func main() {
 			addr := "grpc://localhost:8080"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "grpcs"
@@ -99,7 +99,7 @@ func main() {
 			if *grpcPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *grpcPortF)
 			} else if u.Port() == "" {
@@ -109,7 +109,7 @@ func main() {
 		}
 
 	default:
-		log.Fatalf(ctx, "invalid host argument: %q (valid hosts: localhost)\n", *hostF)
+		log.Fatal(ctx, fmt.Errorf("invalid host argument: %q (valid hosts: localhost)\n", *hostF))
 	}
 
 	// Wait for signal.
diff --git a/codegen/example/testdata/server-same-api-service-name.golden b/codegen/example/testdata/server-same-api-service-name.golden
index f10a89ed..c9039e15 100644
--- a/codegen/example/testdata/server-same-api-service-name.golden
+++ b/codegen/example/testdata/server-same-api-service-name.golden
@@ -64,7 +64,7 @@ func main() {
 			addr := "http://localhost:80"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -75,7 +75,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -88,7 +88,7 @@ func main() {
 			addr := "grpc://localhost:8080"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "grpcs"
@@ -99,7 +99,7 @@ func main() {
 			if *grpcPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *grpcPortF)
 			} else if u.Port() == "" {
@@ -109,7 +109,7 @@ func main() {
 		}
 
 	default:
-		log.Fatalf(ctx, "invalid host argument: %q (valid hosts: localhost)\n", *hostF)
+		log.Fatal(ctx, fmt.Errorf("invalid host argument: %q (valid hosts: localhost)\n", *hostF))
 	}
 
 	// Wait for signal.
diff --git a/codegen/example/testdata/server-sercice-for-only-grpc.golden b/codegen/example/testdata/server-sercice-for-only-grpc.golden
index 066f1130..0bdea129 100644
--- a/codegen/example/testdata/server-sercice-for-only-grpc.golden
+++ b/codegen/example/testdata/server-sercice-for-only-grpc.golden
@@ -64,7 +64,7 @@ func main() {
 			addr := "grpc://localhost:8080"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "grpcs"
@@ -75,7 +75,7 @@ func main() {
 			if *grpcPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *grpcPortF)
 			} else if u.Port() == "" {
@@ -85,7 +85,7 @@ func main() {
 		}
 
 	default:
-		log.Fatalf(ctx, "invalid host argument: %q (valid hosts: localhost)\n", *hostF)
+		log.Fatal(ctx, fmt.Errorf("invalid host argument: %q (valid hosts: localhost)\n", *hostF))
 	}
 
 	// Wait for signal.
diff --git a/codegen/example/testdata/server-server-hosting-multiple-services.golden b/codegen/example/testdata/server-server-hosting-multiple-services.golden
index d24ffcee..fb2c9f99 100644
--- a/codegen/example/testdata/server-server-hosting-multiple-services.golden
+++ b/codegen/example/testdata/server-server-hosting-multiple-services.golden
@@ -70,7 +70,7 @@ func main() {
 			addr := "http://example:8090"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -81,7 +81,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -94,7 +94,7 @@ func main() {
 			addr := "grpc://localhost:8080"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "grpcs"
@@ -105,7 +105,7 @@ func main() {
 			if *grpcPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *grpcPortF)
 			} else if u.Port() == "" {
@@ -115,7 +115,7 @@ func main() {
 		}
 
 	default:
-		log.Fatalf(ctx, "invalid host argument: %q (valid hosts: dev)\n", *hostF)
+		log.Fatal(ctx, fmt.Errorf("invalid host argument: %q (valid hosts: dev)\n", *hostF))
 	}
 
 	// Wait for signal.
diff --git a/codegen/example/testdata/server-server-hosting-service-subset.golden b/codegen/example/testdata/server-server-hosting-service-subset.golden
index 8f8acec3..03b9901a 100644
--- a/codegen/example/testdata/server-server-hosting-service-subset.golden
+++ b/codegen/example/testdata/server-server-hosting-service-subset.golden
@@ -64,7 +64,7 @@ func main() {
 			addr := "http://example:8090"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -75,7 +75,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -88,7 +88,7 @@ func main() {
 			addr := "grpc://localhost:8080"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "grpcs"
@@ -99,7 +99,7 @@ func main() {
 			if *grpcPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *grpcPortF)
 			} else if u.Port() == "" {
@@ -109,7 +109,7 @@ func main() {
 		}
 
 	default:
-		log.Fatalf(ctx, "invalid host argument: %q (valid hosts: dev)\n", *hostF)
+		log.Fatal(ctx, fmt.Errorf("invalid host argument: %q (valid hosts: dev)\n", *hostF))
 	}
 
 	// Wait for signal.
diff --git a/codegen/example/testdata/server-server-hosting-service-with-file-server.golden b/codegen/example/testdata/server-server-hosting-service-with-file-server.golden
index 2e62b9eb..35ce69cd 100644
--- a/codegen/example/testdata/server-server-hosting-service-with-file-server.golden
+++ b/codegen/example/testdata/server-server-hosting-service-with-file-server.golden
@@ -44,7 +44,7 @@ func main() {
 			addr := "http://localhost:80"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -55,7 +55,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -65,7 +65,7 @@ func main() {
 		}
 
 	default:
-		log.Fatalf(ctx, "invalid host argument: %q (valid hosts: svc)\n", *hostF)
+		log.Fatal(ctx, fmt.Errorf("invalid host argument: %q (valid hosts: svc)\n", *hostF))
 	}
 
 	// Wait for signal.
diff --git a/codegen/example/testdata/server-service-for-http-and-part-of-grpc.golden b/codegen/example/testdata/server-service-for-http-and-part-of-grpc.golden
index 06abe18c..6ec133cc 100644
--- a/codegen/example/testdata/server-service-for-http-and-part-of-grpc.golden
+++ b/codegen/example/testdata/server-service-for-http-and-part-of-grpc.golden
@@ -70,7 +70,7 @@ func main() {
 			addr := "http://localhost:80"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -81,7 +81,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -94,7 +94,7 @@ func main() {
 			addr := "grpc://localhost:8080"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "grpcs"
@@ -105,7 +105,7 @@ func main() {
 			if *grpcPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *grpcPortF)
 			} else if u.Port() == "" {
@@ -115,7 +115,7 @@ func main() {
 		}
 
 	default:
-		log.Fatalf(ctx, "invalid host argument: %q (valid hosts: localhost)\n", *hostF)
+		log.Fatal(ctx, fmt.Errorf("invalid host argument: %q (valid hosts: localhost)\n", *hostF))
 	}
 
 	// Wait for signal.
diff --git a/codegen/example/testdata/server-service-for-only-http.golden b/codegen/example/testdata/server-service-for-only-http.golden
index b75f9bd6..58167327 100644
--- a/codegen/example/testdata/server-service-for-only-http.golden
+++ b/codegen/example/testdata/server-service-for-only-http.golden
@@ -63,7 +63,7 @@ func main() {
 			addr := "http://localhost:80"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -74,7 +74,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -84,7 +84,7 @@ func main() {
 		}
 
 	default:
-		log.Fatalf(ctx, "invalid host argument: %q (valid hosts: localhost)\n", *hostF)
+		log.Fatal(ctx, fmt.Errorf("invalid host argument: %q (valid hosts: localhost)\n", *hostF))
 	}
 
 	// Wait for signal.
diff --git a/codegen/example/testdata/server-service-name-with-spaces.golden b/codegen/example/testdata/server-service-name-with-spaces.golden
index 75af0e5c..b7a92773 100644
--- a/codegen/example/testdata/server-service-name-with-spaces.golden
+++ b/codegen/example/testdata/server-service-name-with-spaces.golden
@@ -64,7 +64,7 @@ func main() {
 			addr := "http://localhost:80"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -75,7 +75,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -88,7 +88,7 @@ func main() {
 			addr := "grpc://localhost:8080"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "grpcs"
@@ -99,7 +99,7 @@ func main() {
 			if *grpcPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *grpcPortF)
 			} else if u.Port() == "" {
@@ -109,7 +109,7 @@ func main() {
 		}
 
 	default:
-		log.Fatalf(ctx, "invalid host argument: %q (valid hosts: svc)\n", *hostF)
+		log.Fatal(ctx, fmt.Errorf("invalid host argument: %q (valid hosts: svc)\n", *hostF))
 	}
 
 	// Wait for signal.
diff --git a/codegen/example/testdata/server-single-server-multiple-hosts-with-variables.golden b/codegen/example/testdata/server-single-server-multiple-hosts-with-variables.golden
index eba9a193..74f9b9d7 100644
--- a/codegen/example/testdata/server-single-server-multiple-hosts-with-variables.golden
+++ b/codegen/example/testdata/server-single-server-multiple-hosts-with-variables.golden
@@ -74,12 +74,12 @@ func main() {
 				}
 			}
 			if !versionSeen {
-				log.Fatalf(ctx, "invalid value for URL 'version' variable: %q (valid values: v1,v2)\n", *versionF)
+				log.Fatal(ctx, fmt.Errorf("invalid value for URL 'version' variable: %q (valid values: v1,v2)\n", *versionF))
 			}
 			addr = strings.Replace(addr, "{version}", *versionF, -1)
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -90,7 +90,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -106,7 +106,7 @@ func main() {
 			addr = strings.Replace(addr, "{port}", *portF, -1)
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -117,7 +117,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -127,7 +127,7 @@ func main() {
 		}
 
 	default:
-		log.Fatalf(ctx, "invalid host argument: %q (valid hosts: dev|stage)\n", *hostF)
+		log.Fatal(ctx, fmt.Errorf("invalid host argument: %q (valid hosts: dev|stage)\n", *hostF))
 	}
 
 	// Wait for signal.
diff --git a/codegen/example/testdata/server-single-server-multiple-hosts.golden b/codegen/example/testdata/server-single-server-multiple-hosts.golden
index 5ad3ad26..5762fccd 100644
--- a/codegen/example/testdata/server-single-server-multiple-hosts.golden
+++ b/codegen/example/testdata/server-single-server-multiple-hosts.golden
@@ -63,7 +63,7 @@ func main() {
 			addr := "http://example:8090"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -74,7 +74,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -88,7 +88,7 @@ func main() {
 			addr := "https://example"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -99,7 +99,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -109,7 +109,7 @@ func main() {
 		}
 
 	default:
-		log.Fatalf(ctx, "invalid host argument: %q (valid hosts: dev|stage)\n", *hostF)
+		log.Fatal(ctx, fmt.Errorf("invalid host argument: %q (valid hosts: dev|stage)\n", *hostF))
 	}
 
 	// Wait for signal.
diff --git a/codegen/example/testdata/server-single-server-single-host-with-variables.golden b/codegen/example/testdata/server-single-server-single-host-with-variables.golden
index 200b7918..27e74815 100644
--- a/codegen/example/testdata/server-single-server-single-host-with-variables.golden
+++ b/codegen/example/testdata/server-single-server-single-host-with-variables.golden
@@ -81,7 +81,7 @@ func main() {
 			addr = strings.Replace(addr, "{bool}", *bool_F, -1)
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -92,7 +92,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -114,7 +114,7 @@ func main() {
 			addr = strings.Replace(addr, "{bool}", *bool_F, -1)
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -125,7 +125,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -135,7 +135,7 @@ func main() {
 		}
 
 	default:
-		log.Fatalf(ctx, "invalid host argument: %q (valid hosts: dev)\n", *hostF)
+		log.Fatal(ctx, fmt.Errorf("invalid host argument: %q (valid hosts: dev)\n", *hostF))
 	}
 
 	// Wait for signal.
diff --git a/codegen/example/testdata/server-single-server-single-host.golden b/codegen/example/testdata/server-single-server-single-host.golden
index f921b9a0..7ff78725 100644
--- a/codegen/example/testdata/server-single-server-single-host.golden
+++ b/codegen/example/testdata/server-single-server-single-host.golden
@@ -64,7 +64,7 @@ func main() {
 			addr := "http://example:8090"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -75,7 +75,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -88,7 +88,7 @@ func main() {
 			addr := "https://example:80"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -99,7 +99,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -112,7 +112,7 @@ func main() {
 			addr := "grpc://example:8080"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "grpcs"
@@ -123,7 +123,7 @@ func main() {
 			if *grpcPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *grpcPortF)
 			} else if u.Port() == "" {
@@ -136,7 +136,7 @@ func main() {
 			addr := "http://[::1]:8080"
 			u, err := url.Parse(addr)
 			if err != nil {
-				log.Fatalf(ctx, "invalid URL %#v: %s\n", addr, err)
+				log.Fatalf(ctx, err, "invalid URL %#v\n", addr)
 			}
 			if *secureF {
 				u.Scheme = "https"
@@ -147,7 +147,7 @@ func main() {
 			if *httpPortF != "" {
 				h, _, err := net.SplitHostPort(u.Host)
 				if err != nil {
-					log.Fatalf(ctx, "invalid URL %#v: %s\n", u.Host, err)
+					log.Fatalf(ctx, err, "invalid URL %#v\n", u.Host)
 				}
 				u.Host = net.JoinHostPort(h, *httpPortF)
 			} else if u.Port() == "" {
@@ -157,7 +157,7 @@ func main() {
 		}
 
 	default:
-		log.Fatalf(ctx, "invalid host argument: %q (valid hosts: dev)\n", *hostF)
+		log.Fatal(ctx, fmt.Errorf("invalid host argument: %q (valid hosts: dev)\n", *hostF))
 	}
 
 	// Wait for signal.