Skip to content

Commit 77365c3

Browse files
authored
[crystal-lang] Resolve type check compile error in ApiError (#18759)
* Even with .nil? typecheck, compiler still fails due to .empty? call on nillable type. This appears a poor implementation issue by crystal-lang, but this explicit try avoids the issue for now. * Made call more succinct.
1 parent e6fcbcb commit 77365c3

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

modules/openapi-generator/src/main/resources/crystal/api_error.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module {{moduleName}}
2121
msg = ""
2222
msg = msg + "\nHTTP status code: #{code}" if @code
2323
msg = msg + "\nResponse headers: #{response_headers}" if @response_headers
24-
if @message.nil? || @message.empty?
24+
if @message.try &.empty?
2525
msg = msg + "\nError message: the server returns an error but the HTTP response body is empty."
2626
else
2727
msg = msg + "\nResponse body: #{@message}"

samples/client/petstore/crystal/src/petstore/api_error.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module Petstore
2929
msg = ""
3030
msg = msg + "\nHTTP status code: #{code}" if @code
3131
msg = msg + "\nResponse headers: #{response_headers}" if @response_headers
32-
if @message.nil? || @message.empty?
32+
if @message.try &.empty?
3333
msg = msg + "\nError message: the server returns an error but the HTTP response body is empty."
3434
else
3535
msg = msg + "\nResponse body: #{@message}"

0 commit comments

Comments
 (0)